Summary of my student information management system

Source: Internet
Author: User
Tags stdin
Summary of my student management system

Spent a day in C language to do a student information management system, there are some want to summarize the place, recorded here.
Although it is a simple system, simple to only delete and change the search function, also, the place to save the data is not a database, but a file, but I wrote the idea of a "three-tier architecture" for large projects: The bottom line, the database, and the middle tier, which handles the business logic of user input, and feedback the error to the user, the surface layer, that is, and the interface to the user, accept user input.
Here is a summary of some good code: 1, Judge the keyboard two consecutive input return (can also be used to determine the two consecutive input of a character).

void Back_button ()/* Under the submenu, the user presses the return key two times and returns to the main menu/{printf ("Please press \" Enter button\ "two The Times to back previous menu.\n"); Har ch; Do {while (stdin), ch = getch (), ch!= ' \ R '); if ((ch = getch ()) = = ' \ r ') {break;}} (1); System ("CLS"); } 2, with fgets () to accept screen input information, on the one hand can limit the length of input, on the one hand can also determine whether the user is directly press the ENTER key, or directly press the CTRL+Z.
void Sub_choose_1 ()/* Submenu 1: Search student information based on student's name/{System ("CLS"); char stu_name[stu_name_size]; memset (stu_name,0,stu_name_ SIZE);/* Initializes the string to 0*/loops_search_stu_name:printf ("Please input a name for search: \ n"); Fflush (stdin); Fgets (Stu_name, Stu_name_size, stdin); if (stu_name[0] = = 0) {return;} strprocess (Stu_name);/* Remove the ' \ n ' added by fgets () with/if (strlen (stu_name) = 0) {printf ("Student" s Name cannot empty! Please input again.\n "); Goto Loops_search_stu_name; } Stu_pnode Stu; Stu = Searchstuinfobyname (stulist,stu_name); Showallstuinfo (Stu); Back_button (); } 3, the previous function is the input string error information to judge, this function is the input number of error information to judge.

(To sum up, since the return value of the fgets () is a pointer or null for the input string, it cannot be judged with the return value and cannot be used with a while loop.) The return value of the scanf () function is: When correctly accepted, return the number of accepted, not correctly accepted, return 0, when encountered Ctrl+z, return EOF (that is, 1), so you can use the loop for processing)

void sub_choose_2 ()/* Submenu 2: Search student information according to student number * * {System ("CLS"); int stu_id, input_info, printf ("Please input a sno for search: \ n "); printf ("Sno:"); while (stdin), Input_info = scanf ("%d", &stu_id), Input_info = EOF | | input_info!= 1) {if (Input_info = EOF) {return;} printf ("Sno is a number,please input again.\n"); printf ("Sno:");} Stu_pnode Stu; Stu = Searchstuinfobyid (stulist,stu_id); Showonestuinfo (Stu); Back_button (); } 4, this code, to Fgets () The return value of a very fine division.
loop_modify_name:printf ("Name:"); If

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.