Home > Back-end >  Questions about c language file read and write
Questions about c language file read and write

Time:10-13

First of all, this is the source code, there is no question about the vc compiler


#include
#include
#include
#include
Struct stu
{
Char name [10].
int num;
int age;
Char addr [15].
};//student information structure
Void main ()
{
The FILE * fp.
char ch;
int i;
Boyb struct stu boya [2], [2], * pp, * qq;//pp to boya, qq to boyb
Pp=boya;
Qq=boyb;
If ((fp=fopen (" stu_list1. TXT ", "w +"))==NULL)//open the file
{
Puts (" can't open the file, any key to exit ");
Getch ();
exit(1);
}
Printf (" \ ninput data ");
for(i=0; i<2; I++ pp++)
The scanf (" % s % d % d % s ", pp - & gt; The name, & amp; Pp - & gt; Num, & amp; Pp - & gt; Age, pp - & gt; Addr);
Pp=boya;
for(i=0; i<2; I++ pp++)
{
Fprintf (fp, "% s % d - % d - % s \ n", pp - & gt; The name, pp - & gt; Num, pp - & gt; Age, pp - & gt; Addr);
}

The fclose (fp);
If ((fp=fopen (" stu_list1. TXT ", "rb"))==NULL)
{
Puts (" can't open the file, any key to exit ");
Getch ();
exit(1);
}
The rewind (fp);
for(i=0; i<2; I++ qq++)
{
Fscanf (fp, "% s % d % d % s \ n", qq - & gt; The name, & amp; Qq - & gt; Num, & amp; Qq - & gt; Age, qq - & gt; Addr);
}
Puts (" \ n \ nname \ tnumber age addr \ n ");
Qq=boyb;
for(i=0; i<2; I++ qq++)
{
Printf (" % s \ t % 5 d % d % s \ n ", qq - & gt; The name, & amp; Qq - & gt; Num, & amp; Qq - & gt; Age, qq - & gt; Addr);
}
The fclose (fp);
}

Compile operation is always displayed on the notepad hot has nothing to do with some Numbers, consult ace,
 

CodePudding user response:

On the relationship between Pointers and arrays to find problems

CodePudding user response:

Pointer and file error, and documents stored in the form of a question
  • Related