as i start the program after compiling.... when the user input part comes out... a pop up menu comes out saying.... "mail list.exe stoped working" please help... The code is given below
Code:#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<ctype.h> #include<string.h> #define MAX 10 struct mail{ char name[30]; char country[20]; char state[20]; char city[20]; char email[40]; char phone[15]; }mlist[100]; int init_list(); int enter(); int del(); int list(); int menu_select(); int find_free(); int checkpass(); int main() { char choice,p; init_list(); p= checkpass(); if(p==1){ system("cls"); system("color a"); printf(" PASSWORD GRANTED\n\n"); printf("Now press Enter to get the option."); system("pause>null"); system("cls"); for(;;){ choice= menu_select(); switch(choice){ case 1: enter(); break; case 2: del(); break; case 3: list(); break; case 4: printf("Press enter to exit.");system("pause>null");exit(0); } } } else{ system("cls"); system("color c"); printf("Sorry Access Denied!! You are not an authorised user\n\n"); system("pause>null"); } return 0; } int checkpass() { int ch; char pword[20]; int i = 0; system("color a"); puts ("Please Enter your User password : "); while ((ch = getch()) != EOF && ch != '\n' && ch != '\r' && i < sizeof(pword) - 1) { if (ch == '\b' && i > 0) { printf("\b \b"); i--; } else if (isalnum(ch)) { putchar('*'); pword[i++] = (char)ch; } } if(strcmp(pword,"ad4151206297")==0) return 1; return 0; } int init_list() { register int t; for(t=0; t<MAX; t++) mlist[t].name[0]='\0'; } int menu_select() { char s[80]; int c; system("cls"); system("color b"); printf("Choose any of the option\n\n"); printf("1.Insert an Entry.\t[press 1]\n"); printf("2.Delete an Entry.\t[press 2]\n"); printf("3.Show the list file.\t[press 3]\n"); printf("4.Quit the program.\t[press 4]\n"); do{ printf("Enter your choice: "); gets(s); c= atoi(s); }while(c<0||c>4); return c; } int enter() { int slot; char s[80]; slot = find_free(); system("cls"); if(slot==1){ system("color c"); printf("\nlist full!!Press enter to continue."); system("pause>null"); return 0; } system("color e"); printf("Enter Country: "); scanf("%s",&mlist[slot].country); printf("Enter Name: "); scanf("%s",&mlist[slot].name); printf("Enter State: "); scanf("%s",&mlist[slot].state); printf("Enter City: "); scanf("%s",&mlist[slot].city); printf("Enter Email-id: "); scanf("%s",&mlist[slot].email); printf("Enter Phone Number: "); scanf("%s",&mlist[slot].phone); exit(0); } int find_free() { register int t; for(t=0; mlist[t].name && t<MAX;t++ ); if(t==MAX) return -1; return t; } int del() { register int slot; char s[80]; system("cls"); system("color e"); printf("Enter record # : "); gets(s); slot = atoi(s); if(slot>=0 && slot<MAX) mlist[slot].name[0] = '\0'; system("pause>null"); system("cls"); system("color c"); printf(" ENTRY DELETED\n"); } int list() { register int t; char a; FILE *fp; system("cls"); system("color b"); for(t=0; t<MAX; t++){ if(mlist[t].name[0]){ printf("%s\n", mlist[t].name); printf("%s\n", mlist[t].country); printf("%s\n", mlist[t].state); printf("%s\n", mlist[t].city); printf("%s\n", mlist[t].email); printf("%s\n", mlist[t].phone); } } system("cls"); system("color d"); printf("Print Complete. Do You want to save the Print ??\n\n"); printf("If yes [press y] If no[press n]"); scanf("%d", &a); if(a=='y'|| a=='Y'){ fp = fopen ("Mail list.txt", "w+"); for(t=0; t<MAX; t++){ if(mlist[t].name[0]){ fprintf(fp,"%s\n", mlist[t].name); fprintf(fp,"%s\n", mlist[t].country); fprintf(fp,"%s\n", mlist[t].state); fprintf(fp,"%s\n", mlist[t].city); fprintf(fp,"%s\n", mlist[t].email); } } fclose(fp); printf("SAVE COMPLETE. Press enter to continue"); system("pause>null"); system("cls"); } else { system("cls"); system("color a"); printf("\n\n PRINT ENTER TO EXIT\n"); system("pause>null"); system("cls"); } }