Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- student_information_system_v1.c by Dragan Milicev
- for Ephraim Daniel Villegas
- https://web.facebook.com/eph.nyl
- I don't know how old you are or how well you know the C programming language.
- I see that you programming on mobile phone and that is an impossible job for me.
- You probably can't afford a computer, so you have to do it by mobile phone.
- Congratulations on your hard work and persistence.
- The main problem was that you didn't use
- fflush(stdin);
- While taking an input string with spaces, the buffer does not get cleared
- for the next input and considers the previous input for the same.
- To solve this problem fflush(stdin) is used to clear the stream/buffer.
- Use of fflush(stdin) in C
- https://www.geeksforgeeks.org/use-fflushstdin-c/
- https://stackoverflow.com/questions/2979209/using-fflushstdin
- https://www.quora.com/Why-do-we-use-the-functions-fflush-stdin-and-fflush-stdout-in-c
- You didn't give clear names to the variables and that's why you got lost.
- I suggest you give the names of the variables much like I wrote.
- You have two types of variables, int and string whose length is 20 (LEN is 20).
- Modify my program according to your needs.
- A lot of time is wasted entering data because there is a lot of it.
- It would be good to save data to a file and then read again from that file.
- I don't know if you can work with the files in C.
- C files
- https://www.tutorialspoint.com/cprogramming/c_file_io.htm
- lets_learn_c_files_with_array_of_int_v1.c
- https://pastebin.com/p5mZdKf2
- Since more students will be introduced, it would be good
- to put the data on one student into one structure
- and then work with array of structures.
- I don't know how well you know the structures and pointers in C.
- C structures
- https://www.tutorialspoint.com/cprogramming/c_structures.htm
- lets_learn_structures_in_c_v1.c
- https://pastebin.com/HN1ZSQGr
- For the meny, you have to know Ascii codes of keys
- and how to contrlol the keyboard.
- http://www.asciitable.com/
- key_codes_with_getch()_v1.c
- https://pastebin.com/CTb71BSc
- keyboard_ascii_codes_with_kbhit()_v1.c
- https://pastebin.com/7whsRfyj
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- #define LEN 20 // lenghth of all strings
- int main ()
- {
- int end=0; // because it is not the end, yet
- int choice; // choice from menu
- int StudentsInfo;
- int StudentNo;
- int year;
- char name[LEN];
- char DateOfRegistration[LEN];
- char Surname[LEN];
- char GivenName[LEN];
- char MiddleName[LEN];
- char Program[LEN];
- char Block[LEN];
- char Gender[LEN];
- char CivilStatus[LEN];
- char BirthDate[LEN];
- char BirthPlace[LEN];
- char Religion[LEN];
- char PersonalContactTel[LEN];
- char EmailAddress[LEN];
- char Lrn[LEN];
- char Address[LEN];
- char FathersName[LEN];
- char FathersContact[LEN];
- char MothersName[LEN];
- char MothersContact[LEN];
- char SchoolLastAttended[LEN];
- char YearLastAttended[LEN];
- char GuardiansName[LEN];
- char GuardiansContact[LEN];
- char GuardiansAddress[LEN];
- char EmergencyPersonName[LEN];
- char EmergencyPersonContact[LEN];
- char EmergencyPersonAddress[LEN];
- printf("\n Input your name: ");
- fgets(name,LEN,stdin);
- printf("\n Hi %s welcome to Student information system \n",name);
- while(!end)
- {
- printf("\n Main Menu");
- printf("\n\n 1. Add");
- printf("\n 2. View");
- printf("\n 3. Edit");
- printf("\n 0. End");
- printf("\n Choose operation: ");
- fflush(stdin); // used to clear the buffer and accept the next string
- scanf("%d",&choice);
- switch (choice)
- {
- case 1: // Add
- printf("\n New Student Info's Form \n");
- printf("\n Input students Info: ");
- fflush(stdin); // used to clear the buffer and accept the next string
- scanf("%d",&StudentsInfo);
- printf("\n Date of registration: ");
- fflush(stdin); // used to clear the buffer and accept the next string
- fgets(DateOfRegistration,LEN,stdin);
- printf("\n Student No. : ");
- fflush(stdin); // used to clear the buffer and accept the next string
- scanf("%d",&StudentNo);
- printf("\n Surname: ");
- fflush(stdin); // used to clear the buffer and accept the next string
- fgets(Surname,LEN,stdin);
- printf("\n Given name: ");
- fgets(GivenName,LEN,stdin);
- printf("\n Middle name: ");
- fgets(MiddleName,LEN,stdin);
- printf("\n Program: ");
- fgets(Program,LEN,stdin);
- printf("\n year: ");
- fflush(stdin); // used to clear the buffer and accept the next string
- scanf("%d",&year);
- printf("\n Block: ");
- fflush(stdin); // used to clear the buffer and accept the next string
- fgets(Block,LEN,stdin);
- printf("\n Gender: ");
- fgets(Gender,LEN,stdin);
- printf("\n Civil Status: ");
- fgets(CivilStatus,LEN,stdin);
- printf("\n Birth Date: ");
- fgets(BirthDate,LEN,stdin);
- printf("\n Birth Place: ");
- fgets(BirthPlace,LEN,stdin);
- printf("\n Religion: ");
- fgets(Religion,LEN,stdin);
- printf("\n Personal Contact/Tel : ");
- fgets(PersonalContactTel,LEN,stdin);
- printf("\n Email address: ");
- fgets(EmailAddress,LEN,stdin);
- printf("\n LRN: ");
- fgets(Lrn,LEN,stdin);
- printf("\n Address: ");
- fgets(Address,LEN,stdin);
- printf("\n Fathers name: ");
- fgets(FathersName,LEN,stdin);
- printf("\n Fathers Contact: ");
- fgets(FathersContact,LEN,stdin);
- printf("\n Mothers Name: ");
- fgets(MothersName,LEN,stdin);
- printf("\n Mothers Contact: ");
- fgets(MothersContact,LEN,stdin);
- printf("\n Guardian's Name: ");
- fgets(GuardiansName,LEN,stdin);
- printf("\n Guardians Contact: ");
- fgets(GuardiansContact,LEN,stdin);
- printf("\n School Last Attended: ");
- fgets(SchoolLastAttended,LEN,stdin);
- printf("\n Year Last Attended: ");
- fgets(YearLastAttended,LEN,stdin);
- printf("\n Person to Contact in case of Emergency \n");
- printf("\n Guardian's Name: ");
- fgets(GuardiansName,LEN,stdin);
- printf("\n Guardians Contact: ");
- fgets(GuardiansContact,LEN,stdin);
- printf("\n Guardians Address: ");
- fgets(GuardiansAddress,LEN,stdin);
- printf("\n Emergency Person Name : ");
- fgets(EmergencyPersonName,LEN,stdin);
- printf("\n Emergency Person Contact: ");
- fgets(EmergencyPersonContact,LEN,stdin);
- printf("\n Emergency Person Address: ");
- fgets(EmergencyPersonAddress,LEN,stdin);
- break;
- case 2: // View
- printf("\n Students Information ");
- printf("\n\n Surname: %s",Surname);
- printf("\n Given name: %s",GivenName);
- printf("\n Middle Name: %s",MiddleName);
- printf("\n Program: %s",Program);
- printf("\n Date of registration: %s",DateOfRegistration);
- printf("\n Students Info: %d \n",StudentsInfo);
- printf("\n Student No: %d \n",StudentNo);
- printf("\n Program: %s",Program);
- printf("\n Year: %d \n",year);
- printf("\n Block: %s",Block);
- printf("\n Gender: %s",Gender);
- printf("\n Civil Status: %s",CivilStatus);
- printf("\n BirthDate: %s",BirthDate);
- printf("\n BirthPlace: %s",BirthPlace);
- printf("\n Personal Cel/Tel: %s",PersonalContactTel);
- printf("\n E-mail Address: %s",EmailAddress);
- printf("\n LRN: %s",Lrn);
- printf("\n Address: %s",Address);
- printf("\n\n Father's Name: %s",FathersName);
- printf("\n Fathers Contact: %s",FathersContact);
- printf("\n\n Mother's Name: %s",MothersName);
- printf("\n Mothers Contact: %s",MothersContact);
- printf("\n\n Guardians Name: %s",GuardiansName);
- printf("\n Guardians Contact: %s",GuardiansContact);
- printf("\n\n Person to Contact in Case of Emergency: \n");
- printf("\n Emergency Person Name: %s",EmergencyPersonName);
- printf("\n Emergency Person Contact: %s",EmergencyPersonContact);
- printf("\n Emergency Person Address: %s",EmergencyPersonAddress);
- break;
- case 3: // Edit
- // edit is like add new student or you must use C structure
- // to choose which student will be edited
- break;
- case 0: // if pressed key 0
- end=1; // it is end now
- break;
- default:
- printf("\n You have to choose numbers 0-3 ! \n");
- break;
- } // switch (choice)
- } // while(!end)
- return 0;
- } // main()
- /*
- OUTPUT:
- Input your name: Dragan
- Hi Dragan
- welcome to Student information system
- Main Menu
- 1. Add
- 2. View
- 3. Edit
- 0. End
- Choose operation: 1
- New Student Info's Form
- Input students Info: 2
- Date of registration: 3
- Student No. : 4
- Surname: 5
- Given name: 6
- Middle name: 7
- Program: 8
- year: 9
- Block: 1
- Gender: 2
- Civil Status: 3
- Birth Date: 4
- Birth Place: 5
- Religion: 6
- Personal Contact/Tel : 7
- Email address: 8
- LRN: 9
- Address: 1
- Fathers name: 2
- Fathers Contact: 3
- Mothers Name: 4
- Mothers Contact: 5
- Guardian's Name: 6
- Guardians Contact: 7
- School Last Attended: 8
- Year Last Attended: 9
- Person to Contact in case of Emergency
- Guardian's Name: 1
- Guardians Contact: 2
- Guardians Address: 3
- Emergency Person Name : 4
- Emergency Person Contact: 5
- Emergency Person Address: 6
- Main Menu
- 1. Add
- 2. View
- 3. Edit
- 0. End
- Choose operation: 2
- Students Information
- Surname: 5
- Given name: 6
- Middle Name: 7
- Program: 8
- Date of registration: 3
- Students Info: 2
- Student No: 4
- Program: 8
- Year: 9
- Block: 1
- Gender: 2
- Civil Status: 3
- BirthDate: 4
- BirthPlace: 5
- Personal Cel/Tel: 7
- E-mail Address: 8
- LRN: 9
- Address: 1
- Father's Name: 2
- Fathers Contact: 3
- Mother's Name: 4
- Mothers Contact: 5
- Guardians Name: 1
- Guardians Contact: 2
- Person to Contact in Case of Emergency:
- Emergency Person Name: 4
- Emergency Person Contact: 5
- Emergency Person Address: 6
- Main Menu
- 1. Add
- 2. View
- 3. Edit
- 0. End
- Choose operation: 0
- Process returned 0 (0x0) execution time : 98.336 s
- Press any key to continue.
- */
Advertisement
RAW Paste Data
Copied
Advertisement