Home > Back-end >  C language fprintf functions within the file is messy code
C language fprintf functions within the file is messy code

Time:04-21

Typedef struct bus
{
int num;//the bus route number
Struct Bus * next;//the bus site connection
char name[10];//site name
} bus;
 

//create bus lines
Bus * creat ()
{
Bus * head, * p, * pr;
Char ch=' ';
The head=pr=(bus *) malloc (sizeof (bus));
Pr - & gt; Next=NULL;
Printf (" please enter the serial number of bus lines: ");
The scanf (" % d ", & amp; The head - & gt; Num);
Printf (" please enter the station: ");
While (ch! )
='\ n'{
P=(bus *) malloc (sizeof (bus));
If (head==NULL)
{
The head=p;
}

The else
{
Pr - & gt; Next=p;
Pr=p;
}
Char chance [10].
The scanf (" % s ", p - & gt; Name);
Ch=getchar ();
}
Pr - & gt; Next=NULL;


//the information stored in file
New bus *=head;
The FILE * fp.
Fp=fopen (" C: \ \ Users \ \ Fanyupei \ \ Desktop \ \ bus. TXT ", "a");
If (fp==NULL)
{
Printf (" file open failed!" );
exit(0);
}
//input line information circulation into
Fprintf (fp, "% d", the new - & gt; Num);
While (new - & gt; Next!=NULL)
{
Printf (" % s ", the new - & gt; Name);
Fprintf (fp, "% s", the new - & gt; Name);
New=new - & gt; Next;
}
fclose(fp);
Return the head;
}
  • Related