Home > Back-end >  C language use fread problem while reading the file, for bosses
C language use fread problem while reading the file, for bosses

Time:09-15

Can run in the first two, the third is unable to run, and after reading the three sections of the code if you use printf output to the screen will be garbled, such as file in 20190001, when the output is 959524914, bosses please help have a look, points out the problem,

CodePudding user response:

When reading the third, the m first reset

CodePudding user response:

reference 1/f, Simple, Soft reply:
, while reading the third m first reset
have reset, I this three piece of code is written separately

CodePudding user response:

You add a breakpoint there, have a look at the value of m, debugged, look at the gra

CodePudding user response:

reference 3 floor is Simple - Soft reply:
you add a breakpoint there, have a look at the value of m, debugged, look at the gra
how to add a breakpoint? I just learn c a lot of things, is not very good when it comes to the value of m a third it is not show the value of m, and then end the program directly, as for the first two code value m is less than that in the file, I I have 1000 in the first file data, and then it calculated the m=944; The second should be 100, but only 44; Then I use printf output read data, such as the original file is 20190001, but output is 959524914,

CodePudding user response:

What development tools?

CodePudding user response:

If you have any questions, add my qq: 3405187170 and then send the source code to me, if you can

CodePudding user response:

Simple reference 5 floor - Soft reply:
what development tools?

vs2019

CodePudding user response:

Give a program code, I don't want to enter it again,

CodePudding user response:

Trouble post code and files,
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --./
nine swords dugu, thousands of Buddha, three flowers together, five gas toward the yuan!
nine swords dugu, thousands of Buddha, three flowers together, five gas toward the yuan!
nine swords dugu, thousands of Buddha, three flowers together, five gas toward the yuan!
nine swords dugu, thousands of Buddha, three flowers together, five gas toward the yuan!
nine swords dugu, thousands of Buddha, three flowers together, five gas toward the yuan!

CodePudding user response:

refer to the eighth floor Tryagain2006 response:
give a program code, I don't want to enter it again,

#include
#include
#include
#include
#include
1500/* # define N the number of college students */
# define M/* 60 largest course number */
# define K/* maximum number of results to * 15000/

Typedef struct student
{
Int stuID;
Char stuname [10].
char sex;
int age;
Char department [16].
} STUDENT;/* table one, the basic information of the student */

Typedef struct course
{
Int couID;
Char couname [10].
Char forcou [10].
Int credit;
} COURSE; Table 2/* and course information */

Typedef struct grade
{
Int sID.
Int cID.
Int gra.
} GRADE; *//* table 3, the result information

Void getgra (GRADE gra [], int n)
{
Int I, j;
The FILE * fp3;
for (i=0; i {
Gra [I]. SID=20190001 + I/10;
J=rand () % 50;
Gra [I]. CID=101 + j;
Gra [I]. Gra=((100-40 + 1) * rand ()/(RAND_MAX + 1.0) + 40);
}
If ((fopen_s (& amp; Fp3, "D:/gradata. TXT", "wb +"))!=0)
{
Printf (" can 't open! \n");
return;
}
for (i=0; i <10000; I++)
Fprintf (fp3, "% d - 12-5 d \ \ t % t % 5 d \ t \ n", gra [I]. SID, gra [I] cID, gra [I] gra);
The fclose (fp3);
Printf (" the file has been generated! \n");
}

Void addgra (GRADE gra [])
{
Int I, m=0;
Char ch [2];
The FILE * fp3;
If ((fopen_s (& amp; Fp3, "D:/gradata. TXT", "rb +"))!=0)
{
Printf (" can 't open! \n");
return;
}
The else
{
Printf (" file: students - the course grade information open \ n ");
while (! The feof (fp3))
{
If ((fread (& amp; Gra [m], 12, 1, fp3))==1)
{
Printf (" % d \ n ", gra [m]. SID);
M++;//statistics are recorded for//
}
}
Printf (" now may have % d \ n records ", m);
The fclose (fp3);
}
If (m==0)
Printf (" No record! \n");
If ((fopen_s (& amp; Fp3, "D:/gradata. TXT", "ab"))!=0)
{
Printf (" can 't open! \n");
return;
}
Fread (& amp; Gra [m], 12 m, fp3);
Printf (" input student information? (y/n) : ");
Gets_s (ch);
While (STRCMP (ch, "Y")==0 | | STRCMP (ch, "Y")==0)
{
Printf (" student number: ");
Scanf_s (" % d ", & amp; Gra [m]. SID);
Printf (" course number: ");
Scanf_s (" % d ", & amp; Gra [m]. CID);
Printf (" : ");
Scanf_s (" % d ", & amp; Gra [m]. Gra);
Fprintf (fp3, "% d - 12-5 d \ \ t % t % 5 d \ t \ n", gra [m]. SID, gra [m]. CID, gra [m]. Gra);
Printf (" the information has been saved! \n");
M++;
Printf (" whether to continue? (y/n) : ");
Gets_s (ch);
}
The fclose (fp3);
Printf (" OK! \n");
}

Void main ()
{
GRADE gra [K].
Getgra (gra, 10000);
Addgra (gra);
}
Here is one part, mainly for help questions are inside, if you need other part I the othernullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related