our problem is it only displays 1 record on viewAllRecords() function and delete and edit functions are not working please we need help badlyCode:#include<stdio.h> #include<string.h> #include<conio.h> #include<stdlib.h> typedef struct { char FN[50],LN[50], MI; } fullname; typedef struct student { fullname name; int ID_no, year; char course[30]; struct student *next; } studentinfo; typedef struct book { char title[30], genre[20]; fullname author; int ISBN; struct book *next; }bookinfo; //void pass(); void student(); void addStudent(studentinfo *); void viewAllRecords(studentinfo *); void editRecord(studentinfo *); void deleteRecord(studentinfo *); /* void book(); void addbook(); void viewAllbook(); void deletebook(); void editbook(); */ void menu(); int main() { // pass(); menu(); } /*void pass() { char password[10]; int i; printf("\n Enter Password: "); for(i=0; i<8;i++) { password[i]=getch(); printf("*"); } gets(password); if( password=="sexygirl") { printf("Correct Password!\n"); } else { printf("Password did not match! \n"); printf("Enter Password again!\n"); pass(); } } */ void menu() { int a; printf("\nEnter the number of your choice: \n [1]student \n [2]book \n [3]search \n [4]Exit\n"); scanf("%d",&a); while( a!=3) { switch(a) { case 1:clrscr();student();getch();break; case 2:clrscr();book();getch();break; //case 3:search();getch();break; default:exit(1); } } } void student() { studentinfo *head; int s; printf("\nEnter the number of your choice: \n [1]add student \n [2]delete student \n [3]view all student\n [4]edit student\n [5]Main Menu\n"); scanf("%d",&s); while( s!=6) { switch(s) { case 1:clrscr();addStudent(head);getch();break; case 2:clrscr();deleteRecord(head);getch();break; case 3:clrscr();viewAllRecords(head);getch();break; case 4:clrscr();editRecord(head);getch();break; case 5:clrscr();menu();getch();break; } } } void addStudent(studentinfo *head) { studentinfo *p,*temp; int i,count; FILE *fp; if((fp = fopen("data.dat", "ab"))==NULL) { printf("\nFile not found!"); exit(1); } printf("Enter Number of Students to be added:\n"); scanf("%d",&count); printf("\n===========================================================\n"); head = (studentinfo *) malloc(sizeof(studentinfo)); p=head; for(i=0;i<count;i++) { temp=(studentinfo*)malloc(sizeof(studentinfo)); printf("\nEnter your first name: \n"); fflush(stdin); gets(p->name.FN); printf("Enter your Middle Initial: \n "); scanf("%c",&p->name.MI); printf("Enter your last name: \n"); fflush(stdin); gets(p->name.LN); printf("Enter ID Number: \n "); scanf("%d",&p->ID_no); printf("Enter year level: \n "); scanf("%d",&p->year); printf("Enter your course: \n"); fflush(stdin); gets(p->course); printf("Successfully Added!\n"); fwrite(p,sizeof(*p),1,fp); } p->next=NULL; fclose(fp); clrscr(); student(); } void viewAllRecords(studentinfo *head) { studentinfo *p; FILE *fp; int i; if((fp = fopen("data.dat", "rb"))==NULL) { printf("\nFile not found!"); exit(1); } head = (studentinfo *) malloc(sizeof(studentinfo)); p = head; while(p!=NULL) { fread(p,sizeof(*p),1,fp); printf("\nName: %s",p->name.FN); printf("\t%c.",p->name.MI); printf("\t%s",p->name.LN); printf("\nID NO: %d",p->ID_no); printf("\tCourse & Year: %s-%d\n",p->course,p->year); p = p->next; } fclose(fp); student(); } void deleteRecord(studentinfo *head) { studentinfo *p,*temp; int num; FILE *fp; if((fp = fopen("data.dat", "ab"))==NULL) { printf("\nFile not found!"); exit(1); } printf("Enter ID number of student to be deleted\n"); scanf("%d", &num); head = (studentinfo *) malloc(sizeof(studentinfo)); p=head; while(p->next->ID_no != num) p=p->next; if (p->next != NULL) { temp=p->next; p->next=temp->next; free(temp); } fclose(fp); student(); } void editRecord(studentinfo *head) { studentinfo *p,*temp; int num,a; FILE *fp; if((fp = fopen("data.bnf", "ab+"))==NULL) { printf("\nFile not found!"); exit(1); } head = (studentinfo *) malloc(sizeof(studentinfo)); p=head; printf("Enter ID number of the student to be edited\n"); scanf("%d", &num); while(p->next !=NULL && p->next->ID_no != num) p=p->next; temp=p->next; printf("Enter the number of the item to be edited: \n [1]Student's First Name \n [2]Student's Middle Name \n [3]Student's Last Name\n [4]ID Number \n [5]Year Level \n [6]Course \n [7]Exit\n"); scanf("%d",&a); while( a!=7) { switch(a) { case 1: free(temp->next->name.FN); printf("Enter New First Name:\n"); gets(temp->next->name.FN); fscanf(fp,"\n%s",temp->next->name.FN); getch(); break; case 2: printf("Enter New Middle Name:\n"); scanf("%c", &temp->next->name.MI); fscanf(fp,"\n%c",temp->next->name.MI); break; case 3: free(temp->next->name.LN); printf("Enter New Last Name:\n"); gets(temp->next->name.LN); fscanf(fp,"\n%s",temp->next->name.LN); break; case 4: printf("Enter New ISBN:\n"); scanf("%d",&temp->next->ID_no); fscanf(fp,"\n%d",temp->next->ID_no); break; case 5: printf("Enter New Last Name:\n"); scanf("%d",temp->next->year); fscanf(fp,"\n%d",temp->next->year); break; case 6: free(temp->next->course); printf("Enter New Course"); gets(temp->next->course); fscanf(fp,"\n%s",temp->next->course); case 7: exit(1); break; } } clrscr(); fclose(fp); student(); }