Home > Back-end >  C language VC of files
C language VC of files

Time:12-09

Struct student
{
Int num.
char name[15];
Int score [M];
Float avg.
};
This is to define the structure
Below is the file
Void the file ()
{
int i,j,n;
FILE *fp;
Fp=fopen (" D: \ \ cj TXT ", "w");
If (fp==NULL)
{
Printf (" can't open the file! \n");
The exit (1);
}
for (i=0; iFwrite (& amp; Stu [I], sizeof (struct student), 1, fp);
fclose(fp);
Fp=fopen (" D: \ \ cj TXT ", "rb");
If (fp==NULL)
{
Printf (" can't open the file! \n");
The exit (1);
}
/* printf (" please enter the serial number of the students: ");
The scanf (" % d ", & amp; N);
Printf (" the student id you entered is: % d ", n);
Printf (" find student information is as follows: \ n ");
Fseek (fp, sizeof (n - 1) * (s), 0).
Fread (& amp; S, sizeof (s), 1, fp);
Printf (" % d % s % d % d % d % f ", s.n um, s.n ame, s.s core [0], s.s core [1], s.s core [2]). */

}
Compiled TXT file is messy code, and then by the way, can you help me take a look at/* */errors, thank you

CodePudding user response:

This is not gibberish, you is written according to the way of binary file, if according to the way of the text file to read and write files, you can refer to

https://blog.csdn.net/zhanghaiyang9999/article/details/107032563

CodePudding user response:

If you don't want to "gibberish", it is suggested that using fscanf/fprintf, speaking, reading and writing files,

Commented out part s undefined, n if input is zero, that this is a problem,

CodePudding user response:

reference 1/f, Simple, Soft reply:
this is not gibberish, you is written according to the way of binary file, if according to the way of the text file to read and write files, you can refer to

https://blog.csdn.net/zhanghaiyang9999/article/details/107032563

Specific how to change, not particularly understand

CodePudding user response:

reference 1/f, Simple, Soft reply:
this is not gibberish, you is written according to the way of binary file, if according to the way of the text file to read and write files, you can refer to

https://blog.csdn.net/zhanghaiyang9999/article/details/107032563

Specific how change can you please write a little, not very understand, thank you

CodePudding user response:

Fp=fopen (" D: \ \ cj TXT ", "w"); To read in binary, here have to write binary fp=fopen (" D: \ \ cj TXT ", "wb");
  • Related