Thread: MAIL LIST.exe stopped working

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    1

    MAIL LIST.exe stopped working

    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");
        }
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,631
    Your program has several problems that your compiler should be warning you about. Perhaps you need to increase your compiler warning level and fix the warnings?


    Also you are limiting the number of people that will help you by using so many non-standard operating system specific functions like, getch() and system().

    Here is what my compiler says about your code.

    ||=== Build: Debug in c_homework (compiler: GNU GCC Compiler) ===|
    main.c||In function ‘main’:|
    main.c|42|warning: switch missing default case [-Wswitch-default]|
    main.c||In function ‘checkpass’:|
    main.c|73|error: implicit declaration of function ‘getch’ [-Wimplicit-function-declaration]|
    main.c|73|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
    main.c||In function ‘menu_select’:|
    main.c|116|error: implicit declaration of function ‘gets’ [-Wimplicit-function-declaration]|
    main.c||In function ‘enter’:|
    main.c|141|warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[20]’ [-Wformat=]|
    main.c|144|warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[30]’ [-Wformat=]|
    main.c|147|warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[20]’ [-Wformat=]|
    main.c|150|warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[20]’ [-Wformat=]|
    main.c|153|warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[40]’ [-Wformat=]|
    main.c|156|warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[15]’ [-Wformat=]|
    main.c|126|warning: unused variable ‘s’ [-Wunused-variable]|
    main.c||In function ‘list’:|
    main.c|217|warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘char *’ [-Wformat=]|
    main.c||In function ‘init_list’:|
    main.c|97|warning: control reaches end of non-void function [-Wreturn-type]|
    main.c||In function ‘del’:|
    main.c|191|warning: control reaches end of non-void function [-Wreturn-type]|
    main.c||In function ‘list’:|
    main.c|241|warning: control reaches end of non-void function [-Wreturn-type]|
    ||=== Build failed: 2 error(s), 13 warning(s) (0 minute(s), 0 second(s)) ===|
    The first error is being caused because I had to comment out the <conio.h> inclusion because my compiler doesn't support this operating system specific header file.

    The second error is being caused because I'm using a modern version of the standard which no longer supports the very dangerous gets() function. You should never use this dangerous function, use fgets() instead, and when using scanf() with strings you should use the "optional" width specifier to limit the number of characters this function will try to retrieve, to prevent buffer overflow problems. And be sure you reserve enough room for the mandatory end of string character when you specify the width.

    Code:
        printf("Enter Country: ");
        scanf("%19s",mlist[slot].country); /* Use the proper width specifier to limit the number of characters.
    And remember that scanf(), by default, stops processing strings when it encounters a white space character.


    Jim

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    If you're going to use #defines (good) to declare sizes, at least use them everywhere appropriate.
    Code:
    #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];  //<<< HERE
    You should also have another #define for an error code.
    Code:
        slot = find_free();
        if(slot==1){
            system("color c");
            printf("\nlist full!!Press enter to continue.");
            system("pause>null");
            return 0;
        }
    ...
     
    int find_free()
    {
        register int t;
        for(t=0; mlist[t].name && t<MAX;t++ );
        if(t==MAX)
          return -1;
    These two functions need to agree with one another.

    Your copious (and today, unnecessary) use of register suggests you're learning from someone (or something) with seriously out of date knowledge.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-23-2012, 04:52 AM
  2. ****.exe stopped working (Second project i have)
    By asediugeneral in forum C Programming
    Replies: 3
    Last Post: 09-03-2012, 01:25 PM
  3. ****.exe has stopped working
    By kawaikx15 in forum C Programming
    Replies: 10
    Last Post: 11-19-2011, 07:38 AM
  4. .exe has stopped working
    By bluesky16 in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2011, 12:58 PM
  5. vshost.exe has stopped working
    By Marty21 in forum C# Programming
    Replies: 1
    Last Post: 06-08-2009, 10:41 AM

Tags for this Thread