Home > Back-end >  Pray god to help me have a look at the wrong there
Pray god to help me have a look at the wrong there

Time:03-02

# include
#include
Int main ()
{
Struct student
{
Int num.//salesman code
Int the product;//product code
Int price;//product unit price
Int quantity;//sales
Int the date;//date
X} [100];
The FILE * fp.
Int I, j;
Fopen_s (& amp; Fp, "D: \ \ list. TXT", "r");
For (I=0; i <20; I++)
{
For (j=0; J & lt; 5; J++)
{
Fscanf_s (fp, "% d, % d, % d, % d, % d", & amp; X [I]. The product, & amp; X [I]. Price, & amp; X [I]. Quantity, & amp; X [I] date);
}
}
For (I=0; i <20; I++)
{
For (j=0; J & lt; 5; J++)
{
Printf (" % d, % d, % d, % d, % d ", x [I] num, x [I] product, x [I] price, x [I]. Quantity, x [I] date);
}
}
fclose(fp);

CodePudding user response:

Two inner lining for (j... ) more cycle and fscanf_s () less & amp; X [I]. Num.

CodePudding user response:

Inner loop j useless?

CodePudding user response:

reference 1st floor QZJHJXJ response:
two lining for (j... ) more cycle and fscanf_s () less & amp; X [I]. Num.

Changed or not

CodePudding user response:

reference 1st floor QZJHJXJ response:
two lining for (j... ) more cycle and fscanf_s () less & amp; X [I]. Num.

Only the first listed Numbers

CodePudding user response:

reference 1st floor QZJHJXJ response:
two lining for (j... ) more cycle and fscanf_s () less & amp; X [I]. Num.

File is 20 rows five columns

CodePudding user response:

Fills his belly, and then fill in the file??

CodePudding user response:

Reference:
//description: because the compiler doesn't support fopen_s () and fscanf_s () function, so instead of the corresponding fopen () and fscanf (). 

# include
#include

Struct student
{
Int num.//salesman code
Int the product;//product code
Int price;//product unit price
Int quantity;//sales
Int the date;//date
X} [100];

Int main ()
{
The FILE * fp.
Int I=0, j;

If ((fp=fopen (" D: \ \ list. TXT ", "r"))==NULL) {
Printf (" ERROR: the open file failed! \n");
return 0;
}
While (5==fscanf (fp, "% d, % d, % d, % d, % d",
& X [I]. Num, & amp; X [I]. The product, & amp; X [I]. Price, & amp; X [I]. Quantity, & amp; X [I] date)) {
i++;
}
fclose(fp);

for(j=0; JPrintf (" % d, % d, % d, % d, % d \ n ", x [j]. Journal of num, x [j]. Journal of product, x [j]. Price, x [j]. Journal of quantity, x [j]. J date);

return 0;
}


//101123 45123333202012 2
//102113 45321444202012 2
//please press any key to continue...
  • Related