Home > Back-end >  The structure problems in data input file
The structure problems in data input file

Time:01-13

Hope to have bosses, guide the input data can't write into the file,

CodePudding user response:

Doesn't have good post code directly, an error message is what, what is wavy lines hint, does not contain the corresponding header file?

CodePudding user response:

Reference:
 # include & lt; stdio.h> 
# include & lt; Stdlib. H>

Typedef struct staffmessages {
Long worknum;
char name[10];
Int award;//base pay
Int award1;//position salary
Int award2.//post allowance
Int award3;//special allowance
Int award4;//pay
} the STA.

Int printdata (STA sta1 [])
{
Int I=1, a=0;
For (;; ) {
Printf (" please enter the job number: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % ld ", & amp; Sta1 [a]. Worknum);//scanf_s (" % ld ", & amp; Sta1 [a]. Worknum);
Printf (" please input your name: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % s ", sta1 [a]. Name);//scanf_s (" ", sta1 [a]. Name, sizoef (sta1. [a]. Name));
Printf (" please enter the basic salary: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % d ", & amp; Sta1 [a]. Award);//scanf_s (" % d ", & amp; Sta1 [a]. Award);
Printf (" please enter the position salary: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % d ", & amp; Sta1 [a]. Award1);//scsnf_s (" % d ", & amp; Sta1 [a]. Award1);
Printf (" please enter the post allowance: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % d ", & amp; Sta1 [a]. Award2);//scanf_s (" % d ", & amp; Sta12 [a]. Award2);
Printf (" please enter the special allowance: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % d ", & amp; Sta1 [a]. Award3);//scanf_s (" % d ", & amp; Sta1 [a]. Award3);

Sta1 [a]. Award4=sta1 [a]. Award + sta1 [a]. Award1 + sta1 [a]. Award2 + sta1 [a]. Award3;
Salary: printf (" % d \ n ", sta1 [a]. Award4);
a++;
Printf (" whether to continue the entry (if yes, enter 1, otherwise 0) : ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % d ", & amp; I);//scanf_s (" % d ", & amp; I);
If (I==0) break;
}
Return a;
}

Void writetofile (STA sta1 [], int a)
{
FILE *fp;
int i;
Fp=fopen (" cb. TXT ", "w");
If (fp==NULL) {//if (fopen_s (& amp; Fa, "cb. TXT", "w")==NULL) {
Printf (" Failure to open text ");
exit(0);
}
for(i=0; iFprintf (fp, "% 10 8 ld % s % 5 d % 5 d % d % 5 d % d",
Sta1 [I]. Worknum, sta1 [I]. Name, sta1 [I] award, sta1 [I] award1, sta1 [I] award2, sta1 [I] award2, sta1 [I] award3, sta1 [I] award4);
}
fclose(fp);
}

Int main (void)
{
//the FILE * fp;
The STA STA [100];
Int b;
B=printdata (sta);
Writetofile (sta, b);

return 0;
}

CodePudding user response:

refer to the second floor QZJHJXJ response:
for reference:
 # include & lt; stdio.h> 
# include & lt; Stdlib. H>

Typedef struct staffmessages {
Long worknum;
char name[10];
Int award;//base pay
Int award1;//position salary
Int award2.//post allowance
Int award3;//special allowance
Int award4;//pay
} the STA.

Int printdata (STA sta1 [])
{
Int I=1, a=0;
For (;; ) {
Printf (" please enter the job number: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % ld ", & amp; Sta1 [a]. Worknum);//scanf_s (" % ld ", & amp; Sta1 [a]. Worknum);
Printf (" please input your name: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % s ", sta1 [a]. Name);//scanf_s (" ", sta1 [a]. Name, sizoef (sta1. [a]. Name));
Printf (" please enter the basic salary: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % d ", & amp; Sta1 [a]. Award);//scanf_s (" % d ", & amp; Sta1 [a]. Award);
Printf (" please enter the position salary: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % d ", & amp; Sta1 [a]. Award1);//scsnf_s (" % d ", & amp; Sta1 [a]. Award1);
Printf (" please enter the post allowance: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % d ", & amp; Sta1 [a]. Award2);//scanf_s (" % d ", & amp; Sta12 [a]. Award2);
Printf (" please enter the special allowance: ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % d ", & amp; Sta1 [a]. Award3);//scanf_s (" % d ", & amp; Sta1 [a]. Award3);

Sta1 [a]. Award4=sta1 [a]. Award + sta1 [a]. Award1 + sta1 [a]. Award2 + sta1 [a]. Award3;
Salary: printf (" % d \ n ", sta1 [a]. Award4);
a++;
Printf (" whether to continue the entry (if yes, enter 1, otherwise 0) : ");
The fflush (stdout);
The rewind (stdin);
The scanf (" % d ", & amp; I);//scanf_s (" % d ", & amp; I);
If (I==0) break;
}
Return a;
}

Void writetofile (STA sta1 [], int a)
{
FILE *fp;
int i;
Fp=fopen (" cb. TXT ", "w");
If (fp==NULL) {//if (fopen_s (& amp; Fa, "cb. TXT", "w")==NULL) {
Printf (" Failure to open text ");
exit(0);
}
for(i=0; iFprintf (fp, "% 10 8 ld % s % 5 d % 5 d % d % 5 d % d",
Sta1 [I]. Worknum, sta1 [I]. Name, sta1 [I] award, sta1 [I] award1, sta1 [I] award2, sta1 [I] award2, sta1 [I] award3, sta1 [I] award4);
}
fclose(fp);
}

Int main (void)
{
//the FILE * fp;
The STA STA [100];
Int b;
B=printdata (sta);
Writetofile (sta, b);

return 0;
}

Does not support the scanf in vs,

In addition, fflush (stdout); What's this?

CodePudding user response:

nullnullnullnullnullnullnullnull
  • Related