Home > Back-end >  Who can show me what's the problem
Who can show me what's the problem

Time:09-30

#include
#include
#include
Struct student
{
Char id [10];
char name[10];
Char sex [2];
Char tel [12].
} stu [50];
Int length=0;
The FILE * fp.
Void the save ()//to export structure data into the file
{
//all information in the structure are saved to a file
Fp=fopen (" C: \ \ Users \ \ 12154 \ \ Desktop \ \ 1. TXT ", "w");
int i;
for(i=0; I<=length; I++)
{
Fwrite (& amp; Stu (length), sizeof (struct student), 1, fp);
}
fclose(fp);
}
Void the add ()
{
Printf (" please enter student id you want to add one \ n ", length);
The scanf (" % s ", stu [length]. Id);
Printf (" please input you want to add the names of the people \ n ", length);
The scanf (" % s ", stu [length] name);
Printf (" please input you want to add a person's sex, enter 1 on behalf of the female, enter 2 is for male \ n ", length);
The scanf (" % s ", stu [length] sex);
Printf (" please input you want to add phone \ n ", length);
The scanf (" % s ", stu [length]. Tel);
Printf (" please press 1, save the information without saving, please press 2 \ n ");
int i=0;
for(; I{
If (STRCMP (stu) [r]. Length id, stu [I] id)==0)
{
Printf (" do you want to add existing \ n ");
system("pause");
break;
}
}



Int c;
The scanf (" % d ", & amp; C);
If (c==1)
{
Save ();
Length++;
}
}
Void del () a student id//input, delete this message
{
Char s [10];
Printf (" please enter student id you want to delete the \ n ");
The scanf (" % s ", s);
int i;
for(i=0; I{
If (STRCMP (s, stu [I] id)==0)
{
Printf (" do you want to delete the record information: student id % s, % s name, gender, % s, cell phone % s ", I + 1, stu [I] id, stu [I]. Name, stu [I] sex, stu [I]. Tel);
break;
}
}
If (I==length) printf (" do you want to delete the student number does not exist \ n ");
Int j;
For (j=I; J<=length;) ;



}
Void the update () a student id//s input, update his information
{
int i,j;
Char s [10];
Printf (" please enter a query student id: \ n ");
The scanf (" % s ", s);
for(j=0; JIf (STRCMP (s, stu [j]. Id)==0)
{
Printf (" gender: name, student id: % s % s % s telephone: % s \ n, stu [j]. Journal of id, stu [j]. Name, stu [j]. Journal of sex, stu [j]. Tel ");
Printf (" please enter the student id modified name \ n "); The scanf (" % s ", stu [j]. Name);
Printf (" please enter the student id change gender \ n "); The scanf (" % s ", stu [j]. Journal of sex);
Printf (" please enter the student id to modify phone \ n "); The scanf (" % s ", stu [j]. Tel);
Printf (" save the changes, please press 1, do not save, please press 2 \ n ");
Int c;
The scanf (" % d ", & amp; C);
If (c==1)
{
Save ();
Printf (" success ");
}
break;
}
If (j==length) printf (" no such person ");
system("pause");


}

Void the search () a student id//input, according to his information
{
Char s [10];
Printf (" 1. According to the student id accurate search; 2. According to the fuzzy lookup name ");
Int I, j, c;
Printf (" please input your choice \ n ");
The scanf (" % d ", & amp; C);
If (c==1)
{
Printf (" please enter a query student id: \ n ");
The scanf (" % s ", & amp; S);
for(j=0; JIf (STRCMP (s, stu [j]. Id)==0) printf (" gender: name, student id: % s % s % s telephone: % s \ n ", stu [j]. Journal of id, stu [j]. Name, stu [j]. Journal of sex, stu [j]. Tel);
}
If (c==2)
{
Printf (" please input your name; \n");
The scanf (" % s ", & amp; S);
for(j=0; J{
If (STRSTR (stu [j]. Name, s)) printf (" gender: name, student id: % s % s % s telephone: % s \ n ", stu [j]. Journal of id, stu [j]. Name, stu [j]. Journal of sex, stu [j]. Tel);

}
}

Void the show ()//show all information now
{
int i;
for(i=0; I<=length; I++)
{
Printf (" % d a classmate: student id % s, % s name, gender, % s, cell phone % s ", I + 1, stu [I] id, stu [I]. Name, stu [I] sex, stu [I]. Tel);
}
system("pause");//system suspend
}
Void init ()//the information from the file into the structure array
{
Length=0;
Fp=fopen (" C: \ \ Users \ \ 12154 \ \ Desktop \ \ 1. TXT ", "r");//read the desktop 1. TXT
//loop read
int i=0;
While (fread (& amp; Stu [I], sizeof (struct student), 1, fp)==1)
{
i++;
}
fclose(fp);
Length=I;
Printf (" there are records, % d ", length);
}
Void cover ()//menu interface
{
printf("\n");
Printf (" * * * * * * * * * * * * * * * ");
Printf (" welcome to use the address book system ");
Printf (" * * * * * * * * * * * * * * * ");
printf("\n");
Printf (" * 1: add information * \ n ");
Printf (" * * * * 2: delete information \ n ");
Printf (" * * * * * * 3: modify information \ n ");
Printf (" * * * * 4: query information * * * * \ n ");
Printf (" * * * * * 5: display all information * * * * * \ n ");
Printf (" * * * * * * 6: save the information * * * * * * \ n ");
Printf (" * * * * * * * 0: out of * * * * * * * \ n ");
}



Void excel ()
{
int i;
Fp=fopen (" C: \ \ Users \ \ 86150 \ \ Desktop ", "w");
for (i=0; I{
Fprintf (fp, "% s, % s, % s, % s \ n", stu [I] id, stu [I]. Name, stu [I] sex, stu [I]. Tel);

}
fclose(fp);
system("pause");
}


Int main ()
{
int i; Is a function//I number
Cover ();//display
init();//the current number of information, the file information to the struct array
Printf (" please input your choice number \ n ");
The scanf (" % d ", & amp; I);
The switch (I)
{
Case 1: add (); break;
Case 2: del (); break;
Case 3: the update (); break;
Case 4: search (); break;
Case 5: show (); break;
Case 6: save (); break;
Case: 0 exit (0); break;
Default: printf (" you input is wrong, please input again \ n ");
}
}


















CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related