Home > Back-end >  Why is the code after storage file? For big solutions
Why is the code after storage file? For big solutions

Time:03-06

#include #include #include Struct Telephone {char number [20]. Char name [20]. Char sex [20]. Char age [20]. Char speciaity [20]. Char Class [20]. Struct Telephone * next; }; Typedef struct Telephone TEL; TEL * head=NULL; Void showmenu ();//the menu void Appenditem ();//to add student information void print ();//browse all student information void Finditem1 ();//to find student information (by student id) void Finditem2 ();//to find student information (by name) void Removeitem ();//delete student information void Saveandfree ();//save to file void Open ();//open file void main () {char ch; The Open ();//open the file while (1) {showmenu ();//display the menu the scanf (" % c ", & amp; Ch); The switch (ch) {case '1' : Appenditem ();//to add student information break; Case '2' : print ();//information through all of the students break; Case: '3' Finditem1 ();//to find students information 1. According to the student id break; Case '4' : Finditem2 ();//to find student information (2) by name break; Case '5' : Removeitem ();//delete student information information print (); Results after deleting//output break; Case '0' : Saveandfree ();//save and free memory exit (0);//break out system; Default: printf (" choose wrong!" ); break; }}}//menu void showmenu () {printf (" \ n * * * * * * * * * * * * * * * * * welcome to use the student information management system * * * * * * * * * * * * * * * * * \ n "); Printf (" \ n * * * * * * * * * * * * * * * * * according to the main menu prompted to select desired operation * * * * * * * * * * * * * * * * * \ n "); Printf (" \ n \ t1 to add student information); Printf (" \ n \ t2. Through all of the students information "); Printf (" \ t3. According to the student id information query students \ n "); Printf (" \ t4 by name query student information \ n "); Printf (" \ n \ t5 delete student information); Printf (" \ t0. Save and exit system! \n"); Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n "); Printf (" \ t please select: \ n "); }//to add student information void Appenditem () {p1=NULL, TEL * * p2=NULL; P1=(TEL *) malloc (sizeof (TEL));//application node printf (" input student id: \ n ");//add information the scanf (" % s ", p1 - & gt; Number); Printf (" input name: \ n "); The scanf (" % s ", p1 - & gt; Name); Printf (" input gender: \ n "); The scanf (" % s ", p1 - & gt; Sex); Printf (" input age: \ n "); The scanf (" % s ", p1 - & gt; The age); Printf (" input professional: \ n "); The scanf (" % s ", p1 - & gt; Speciaity); Printf (" input class: \ n "); The scanf (" % s ", p1 - & gt; The Class); P1 - & gt; Next=NULL;//save to list the if (head==NULL) {head=(TEL *) malloc (sizeof (TEL));//the application space head - & gt; Next=p; } else {for (p2=head; The p2 - & gt; Next!=NULL; The p2=p2 - & gt; Next);//find node p2 - & gt; Next=p; } printf (" this information has been added!" ); }//browse all student information void print () {TEL * p=NULL; If (head==NULL) {printf (" no record in the student information management system, please use this function after the input record! \n"); return; } printf (" * * * * * * * * * * * * * * the student information management system * * * * * * * * * * * * * * * * * * * * * \ n ");//output information printf (" student id \ \ t t name gender \ professional \ \ t t t age class \ n "); For (p=head - & gt; next; p!=NULL; P=p - & gt; Next) printf (" % s \ \ t t % s % s % s \ \ t \ n \ t t % s % s ", p - & gt; Number, p - & gt; The name, p - & gt; Sex, p - & gt; Age, p - & gt; Speciaity, p - & gt; The Class); }//to find students information 1. According to the student id void Finditem1 () {TEL * p; Char findname [20]. Printf (" please enter to find student id: \ n "); The scanf (" % s ", findname); Printf (" * * * * * * * * * * * * * * the student information management system * * * * * * * * * * * * * * * * * * * * * \ n "); Printf (" student id \ \ t t name gender \ professional \ \ t t t age class \ n "); For (p=head - & gt; next; p!=NULL; P=p - & gt; {if STRCMP (next) (p - & gt; Number, findname)==0) printf (" % s \ \ t t % s % s % s \ \ t \ n \ t t % s % s ", p - & gt; Number, p - & gt; The name, p - & gt; Sex, p - & gt; Age, p - & gt; Speciaity, p - & gt; The Class); }}//to find students information 2. According to the name void Finditem2 () {TEL * p; Char name [20]. Printf (" please enter a name to find: \ n "); The scanf (" % s ", name); Printf (" * * * * * * * * * * * * * * the student information management system * * * * * * * * * * * * * * * * * * * * * \ n "); Printf (" student id \ \ t t name gender \ professional \ \ t t t age class \ n "); For (p=head - & gt; next; p!=NULL; P=p - & gt; {if STRCMP (next) (p - & gt; Name, name)==0) printf (" % s \ \ t t % s % s % s \ \ t \ n \ t t % s % s ", p - & gt; Number, p - & gt; The name, p - & gt; Sex, p - & gt; Age, p - & gt; Speciaity, p - & gt; The Class); }}//delete student information void Removeitem () {char findname [20].//delete after first find TEL * p=head - & gt; Next, * pr=head - & gt; next; Printf (" please enter to delete student id: \ n "); The scanf (" % s ", & amp; Findname); If (the head - & gt; Next==NULL) {printf (" this node. \n"); return; } while ((STRCMP (p - & gt; The name, findname)!=0) & amp; & P - & gt; Next!=NULL) {pr=p; P=p - & gt; next; } the if (STRCMP (findname, p - & gt; Name)==0)//output delete information {printf (" % s \ \ t t % s % s % s \ \ t \ n \ t t % s % s ", p - & gt; Next - & gt; Number, p - & gt; Next - & gt; The name, \ p - & gt; Next - & gt; Sex, p - & gt; Next - & gt; Age, p - & gt; Speciaity, p - & gt; The Class); If (p==head - & gt; Next) head - & gt; Next=p - & gt; next; The else pr - & gt; Next=p - & gt; next; Free (p); } printf (" this information has been deleted!" ); }//save the list information to a file and release the memory space void Saveandfree () {TEL * p=NULL; FILE *fp; Char * Book="books. TXT"; If (head==NULL) {printf (" \ n record is empty! \n"); return; } the else p=head - & gt; next; If ((fp=fopen (Book, wb + ""))==NULL) {printf (" \ n can't open the file! \n"); return; } while (p!=NULL) {//save information fwrite (p, sizeof (TEL), 1, fp); P=p - & gt; next; } printf (" saved!" ); The fclose (fp);//* * * * * * * * * * release chain table space for (; The head - & gt; Next!=NULL;) {p=head - & gt; next; The head - & gt; Next=head - & gt; Next - & gt; next; Free (p); } free (the head); }//FILE information output to the linked list void Open () {FILE * fp; P1=NULL, TEL * * p2=NULL, * temp=NULL; If ((fp=fopen (" books. TXT ", "rb +"))==NULL) {printf (" \ n * * * * * * * * * * * * * * * * this is a new student information management system of * * * * * * * * * * * * * * * * * * \ n "); return; } the head=(TEL *) malloc (sizeof (TEL)); The head - & gt; Next=NULL; Temp=p2=head; while(! Feof (fp))//loop reads {p1=(TEL *) malloc (sizeof (TEL)); Temp=p2; The p2 - & gt; Next=p; P1 p2=; Fread (p1, sizeof (TEL), 1, fp); } temp - & gt; Next=NULL; The fclose (fp);//close the file}

CodePudding user response:

Why love so send code? She looked at the code ugly understand logic? ~

CodePudding user response:

 # include 
#include
#include

Struct Telephone {
Char number [20].
Char name [20].
Char sex [20].
Char age [20].
Char speciaity [20].
Char Class [20].

Struct Telephone * next;
};

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related