This is my first practical project. I use all the knowledge on the book. I don't have much complicated knowledge and I didn't learn the knowledge of C language graphics, so the interface is ugly, this is the case for the moment.
Source file:
# Include <stdio. h> # include <string. h> # include <stdlib. h> # include "student. h "void main () {int num_order; char c; num_order = msg (); // output the relevant information and obtain the related operation while (num_order! = 1 & num_order! = 2 & num_order! = 3) {printf ("enter the correct parameter again: \ n"); scanf ("% d", & num_order);} switch (num_order) {case 1: from_file (0); break; // query case 2: input _ (); break; // input case 3: from_file (1); break; // modify} c = getchar (); // used to accept the previous carriage return printf ("\ n do you want to perform other operations? \ N is/Y, NO/N \ n "); c = getchar (); while (c = 89 | c = 121) {printf ("Enter the relevant parameter \ n"); scanf ("% d", & num_order); switch (num_order) {case 1: from_file (0); break; // query case 2: input _ (); break; // input case 3: from_file (1); break; // modify} c = getchar (); printf ("\ n do you want to perform other operations? \ N is/Y, NO/N \ n "); c = getchar ();}}
Student. h header file:
# Include <stdio. h> # include <string. h> # include <stdlib. h> int msg (); // message Prompt window void input _ (); // enter the relevant information void save_files (struct Student_info * p ); // Save the content to the file void print _ (struct Student_info * p, int n); // output the content to the screen void from_file (int flag ); // read the file content void change_info (struct Student_info * p, int loop); // modify the relevant content void sort_info (struct Student_info * p ); // sort struct Student_info {char name [10]; int id; int age; char Adress [30] ;}; int num_stud; int msg () // information Prompt window {int n; printf ("\ t student management system \ n"); printf ("\ t please enter the operation you want to perform: \ n "); printf (" \ t ╭ ═ \ n "); printf ("\ t limit 1. student Information Query limit \ n "); printf (" \ t limit 2. student Information entry limit \ n "); printf (" \ t limit 3. modify student information (\ t "); scanf ("% d", & n); return (n);} void input _ () // enter the relevant information {int I; struct Student_info * p, * pai_save; system ("cls"); printf ("Student Information entry system: \ N "); printf (" Enter the number of students to enter information \ n "); scanf (" % d ", & num_stud ); if (cmd_save = p = (struct Student_info *) malloc (num_stud * sizeof (struct Student_info) = NULL) printf ("failed to create a space! \ N "); else printf (" Enter student ID name age address \ n "); for (I = 0; I <num_stud; I ++, p ++) {scanf ("% d % s", & p-> id, p-> name, & p-> age, p-> adress );} save_files (cmd_save);} void save_files (struct Student_info * p) // Save the content {int I; FILE * fp; if (fp = fopen ("stud. dat "," AB "))! = NULL) {for (I = 0; I <num_stud; I ++, p ++) {fwrite (p, sizeof (struct Student_info), 1, fp );} fclose (fp); printf ("Information entry complete! \ N ");} else if (fp = fopen (" stud. dat "," wb ") = NULL) {printf (" file creation failed! \ N "); exit (0) ;}else {for (I = 0; I <num_stud; I ++, p ++) {fwrite (p, sizeof (struct Student_info), 1, fp) ;}fclose (fp); printf ("Information entry completed! \ N ") ;}} void print _ (struct Student_info * p, int n) // output screen {int I; printf ("student ID \ t name \ t age \ t address \ n"); for (I = 0; I <n; I ++, p ++) {printf ("%-4d % 7 s % 6d % 8s \ n", p-> id, p-> name, p-> age, p-> adress );} printf ("\ n");} void from_file (int flag) // read the FILE content {FILE * fp; struct Student_info temp; struct Student_info * p, * pai_print, * first; int I = 0; int loop = 0; system ("cls"); printf ("\ t student information query \ n"); if (f P = fopen ("stud. dat", "rb") = NULL) {printf ("the file information does not exist \ n"); exit (0) ;}while (! Feof (fp) {fread (& temp, sizeof (struct Student_info), 1, fp); loop ++;} loop-= 1; // obtain the number of files in rewind (fp); first = pai_print = p = (struct Student_info *) malloc (loop * sizeof (struct Student_info); for (I = 0; I <loop; I ++, p ++) {fread (p, sizeof (struct Student_info), 1, fp);} print _ (pai_print, loop ); if (flag = 0) {free (first); first = pai_print = p = NULL;} else {change_info (first, Loop);} fclose (fp);} void change_info (struct Student_info * p, int loop) {int n, I; struct Student_info * t1, * t2; FILE * fp; printf ("Enter the student ID to modify student information: \ n"); scanf ("% d", & n); t2 = t1 = p; for (I = 0; I <loop; I ++, t1 ++) {if (t1-> id = n) break;} scanf ("% d % s ", & t1-> id, t1-> name, & t1-> age, t1-> adress); if (fp = fopen ("stud. dat "," wb ") = NULL) {printf (" file write error! \ N ") ;}else {for (I = 0; I <loop; I ++, p ++) {fwrite (p, sizeof (struct Student_info), 1, fp) ;}} fclose (fp); printf ("modification successful! \ N "); free (t2 );}
Running interface:
1. Home Page
2. Input Interface
3. query interface
4. Modify the interface
Note that the student ID 102 has changed.
Link to the attached file:
Link: http://pan.baidu.com/s/1sjjSpy9 password: kowr