Thread: Need help with fixing modules

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    6

    Post Need help with fixing modules

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define num_shoes 10
    
    
    
    typedef struct
            {
            int code;
            char name[80];
            float price;
            }record;
    
    int authentication (int tries)
    {
        char comparison[20],junk[80];
        char username [20]="";
        printf("please enter a valid username. (%d tries left)>",3-tries);
        scanf("%s",username);
        getchar();
        FILE * memberfile =fopen("Memberfile.txt","r");
        for (;memberfile != NULL && !feof (memberfile);)
            {
                         comparison[0]=0;
                         fscanf(memberfile,"%s",comparison);
                         if(strcmp(comparison,username)==0)
                              {
                                 fclose(memberfile);
                                 return 1;
                              }  
                         else fgets(junk,80,memberfile);/*reads any remaining characters 
                         on that line and goes down to the new line*/ 
            }
    return 0;        
    }                                                                          
    
    int search_code (record array [] ,int seeked)
    {
        int index =0;
        for (index =0; index < num_shoes; index++)
            {
                   if (!array[index].name[0])
                   continue;/* if the first character of the name is 0 (no name)
                   then continue forward and skip the comparison. repeat the loop*/
                   if (array[index].code ==seeked)
                   return index;
            }
    return -1;
    }
    /*the following will search the array for an item using the name as the search field
    if the item is not found it returns -1*/
    int search_name (record array[],char name[])
    {
       for (int index =0; index<num_shoes;index++) 
        {
            if (strcasecmp (name,array[index].name)==0)
            return index;
        }
    return -1;
    }
    
    float calculations (record item, int index)
    {
    int code_of_shoes;
    float amount_of_money;
    printf("\nhow many items do you want?");
    scanf("%d",&code_of_shoes);getchar();
    printf("cost : $%0.2f\n",item.price*code_of_shoes);
    printf("\n how much money are you paying?");
    scanf("%f",&amount_of_money);getchar();
    printf("\n Your change is :$%.2f\n",amount_of_money-(item.price*code_of_shoes));
    }
    
    
    
    void display_record (record item, int index)
    {
    int i;
    printf("%-4d %20s\t",item.code,item.name);
    printf("%-4.f\t",item.price);
    printf("\n");
                
    }
    
    int main (void)
    {
    int i, j,code_of_items;
    float amount_of_money;
    record items [num_shoes] ={0};//initialise all locations to zero
    char junk;
    int menu_code;
    
    for (j=0; j<3 &&!authentication(j);j++);/*this loops the authentication of the 
                                             user and gives him 5 triesto enter a valid      
                                             user name*/
     if (j==3)                              
       {
             printf("you have been booted from the system please restart\n");
             getchar();
             return -1;
       }
    else printf("welcome to the system\n");
    
    FILE * f =fopen("shoes.txt","r");
    if(!f)
          {
              printf("the file could not be found, create a file\n");
              getchar();
              return 1;//in the main function this means there was an error
          }
    for (i=0; i<num_shoes &&!feof(f);i++);
        {
              fscanf(f,"%d",&items[i].code);
              fscanf(f,"%f",&items[i].price);
              //fscanf(f,"%s",&items[i].colour);
    /*the fscanfs above will leave a single space on the line, just like a getchar()
    used after a scanf, afgetc must be used here to remove the space otherwise the 
    name read from the file will have a space at the front of it and the program will
    not find the name sought*/     
              fgetc(f);
              fgets(items[i].name,80,f);  
    /*the above line will pick up a maximum of 80 characters from the file, stopping 
    only when 80 chractersare picked up OR a newline character is picked up. The newline 
    remains in the item[i].name string, and must be removed*/          
              items[i].name [strlen(items[i].name) -1] =0;
    /*the line above will use the index 'strlen(items[i].name)' (the length of the name)
    minus ONE space,which would be the second last charcter,and sets the end of the string 
    to that new point,effectively cutting ogg the last character from it*/
    
        }
    fclose(f);
    
    do
         {
              fflush(stdin);/*clear the input buffer BEFORE reading,just in case 
                              there'sanything there left over from the previous run*/
                                    
              printf("\n\n1 - search on code \n2 -search on name \n3 - finish \n\n>");
              getchar();
              switch (menu_code)
                     {
                        case 1:
                             {
                                int item_code, index_return;
                                printf("which item code?>");
                                scanf("%d",&item_code);
                                getchar();
                                index_return = search_code(items,item_code);
                                if (index_return <0)
                                   {
                                       printf("NOT FOUND!");
                                       break;
                                   }
                                 display_record(items[index_return],index_return);
                                 calculations(items[index_return],index_return);
                                 break;
                                } 
                         case 2:
                              {
                                 int index_return=0;
                                 char item_name[100] ="";
                                 printf("which item name");
    /*A simple scanf will not work here because the names have spaces,therefore we
    will use an fgets() with the file as 'stdin'. This represents standard input
    and is representative of the console. The line below means get a maximum of 80 
    characters from the user and stores it in 'item_name' like the previous fgets,
    the end must be cut off.*/
                                 fgets(item_name,80,stdin);
                                 item_name[strlen(item_name)-1] =0;
    /*The end of a string is represented by a 0 character setting
    a character in a string to 0 moves the end of the string*/                          
                                 index_return =search_name(items,item_name);
                                 if(index_return <0)
                                 {
                                   printf("NOT FOUND!");
                                   break;
                                 }
                                 display_record(items[index_return],index_return);
                                 calculations(items[index_return],index_return);
                                 break;
                              }
                              
                         case 3:                          
                                {
                                 printf("exting\n");
                                 break;
                                }
                         default:printf("invalid choice, please try again\n\n");
                                 break;
                                 }
                         system("pause");
                         system("cls");
                         }while(menu_code!= 3);
                         
    
    }

  2. #2
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Umm...you need to tell us what's going wrong so we can know what to look for. We're not going to do your work for you.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    6
    umm i dont know the specific problem. I know for sure that something is wrong with either the case statements or the module Search_colour. the problem only occured when i added that module before it was fine. i am getting an error when i run it like if i entered an invalid choice like 9 or something

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    6

    Post added modules

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define num_shoes 10
    
    
    
    typedef struct
            {
            int code;
            char name[80];
            float price;
            char colour [10];
            }record;
    int authentication (int tries)
    {
        char comparison[20],junk[80];
        char username [20]="";
        printf("please enter a valid username. (%d tries left)>",3-tries);
        scanf("%s",username);
        getchar();
        FILE * memberfile =fopen("Memberfile.txt","r");
        for (;memberfile != NULL && !feof (memberfile);)
            {
                         comparison[0]=0;
                         fscanf(memberfile,"%s",comparison);
                         if(strcmp(comparison,username)==0)
                              {
                                 fclose(memberfile);
                                 return 1;
                              }  
                         else fgets(junk,80,memberfile);/*reads any remaining characters 
                         on that line and goes down to the new line*/ 
            }
    return 0;        
    }                                                                          
    
    int search_code (record array [] ,int seeked)
    {
        int index =0;
        for (index =0; index < num_shoes; index++)
            {
                   if (!array[index].name[0])
                   continue;/* if the first character of the name is 0 (no name)
                   then continue forward and skip the comparison. repeat the loop*/
                   if (array[index].code ==seeked)
                   return index;
            }
    return -1;
    }
    /*the following will search the array for an item using the name as the search field
    if the item is not found it returns -1*/
    
    int search_colour (record array[],char colour[])
    {
        for (int index=0; index<num_shoes;index++)
        {
        if (strcmp (colour,array[index].colour)==0)
        return index;
        }
    return -1;
    }
    
    int search_name (record array[],char name[])
    {
       for (int index =0; index<num_shoes;index++) 
        {
            if (strcasecmp (name,array[index].name)==0)
            return index;
        }
    return -1;
    }
    
    
        
    float calculate_change (record item, int index)
    {
    int number_of_shoes;
    float amount_of_money;
    printf("\nhow many items do you want?");
    scanf("%d",&number_of_shoes);getchar();
    printf("cost : $%0.2f\n",item.price*number_of_shoes);
    printf("\n how much money are you paying?");
    scanf("%f",&amount_of_money);getchar();
    printf("\n Your change is :$%.2f\n",amount_of_money-(item.price*number_of_shoes));
    
    }
    
    
    
    void display_record (record item, int index)
    {
    int i;
    printf("%-4d %20s\t",item.code,item.name);
    printf("%-4.f\t",item.price);
    printf("%-4d\t",item.colour);
    printf("\n");
                
    }
    
    int main (void)
    {
    int i, j,number_of_items;
    float amount_of_money;
    record items [num_shoes] ={0};//initialise all locations to zero
    char junk;
    int menu_code;
    
    for (j=0; j<3 &&!authentication(j);j++);/*this loops the authentication of the 
                                             user and gives him 5 triesto enter a valid      
                                             user name*/
     if (j==3)                              
       {
             printf("you have been booted from the system please restart\n");
             getchar();
             return -1;
       }
    else printf("welcome to the system\n");
    
    FILE * f =fopen("shoes.txt","r");
    if(!f)
          {
              printf("the file could not be found, create a file\n");
              getchar();
              return 1;//in the main function this means there was an error
          }
    for (i=0; i<num_shoes &&!feof(f);i++);
        {
              fscanf(f,"%d",&items[i].code);
              fscanf(f,"%f",&items[i].price);
              fscanf(f,"%s",items[i].colour);
    /*the fscanfs above will leave a single space on the line, just like a getchar()
    used after a scanf, afgetc must be used here to remove the space otherwise the 
    name read from the file will have a space at the front of it and the program will
    not find the name sought*/     
              fgetc(f);
              fgets(items[i].name,80,f);  
    /*the above line will pick up a maximum of 80 characters from the file, stopping 
    only when 80 chractersare picked up OR a newline character is picked up. The newline 
    remains in the item[i].name string, and must be removed*/          
              items[i].name [strlen(items[i].name) -1] =0;
    /*the line above will use the index 'strlen(items[i].name)' (the length of the name)
    minus ONE space,which would be the second last charcter,and sets the end of the string 
    to that new point,effectively cutting ogg the last character from it*/
    
        }
    fclose(f);
    
    do
         {
              fflush(stdin);/*clear the input buffer BEFORE reading,just in case 
                              there'sanything there left over from the previous run*/
                                    
              printf("\n\n1 - search on code \n2 -search on colour \n3 - search on name \n4 - finish \n\n>");
              getchar();
              switch (menu_code)
                     {
                        case 1:
                             {
                                int shoe_code, index_return;
                                printf("which shoe code?>");
                                scanf("%d",&shoe_code);
                                getchar();
                                index_return = search_code(items,shoe_code);
                                if (index_return <0)
                                   {
                                       printf("NOT FOUND!");
                                       break;
                                   }
                                 display_record(items[index_return],index_return);
                                 calculate_change(items[index_return],index_return);
                                 break;
                                } 
                         
                         case 2:
                              {
                                int index_return;
                                char shoe_colour[10]="";
                                printf("which shoe colour?>");
                                scanf("%s",shoe_colour);
                                index_return=search_name(items,shoe_colour);
                                if (index_return<0)
                                   {
                                      printf("NOT FOUND!");
                                      break;
                                   }
                                display_record(items[index_return],index_return);
                                calculate_change(items[index_return],index_return);
                                break;
                                }
                         
                         
                         case 3:
                              {
                                 int index_return=0;
                                 char item_name[100] ="";
                                 printf("which item name");
    /*A simple scanf will not work here because the names have spaces,therefore we
    will use an fgets() with the file as 'stdin'. This represents standard input
    and is representative of the console. The line below means get a maximum of 80 
    characters from the user and stores it in 'item_name' like the previous fgets,
    the end must be cut off.*/
                                 fgets(item_name,80,stdin);
                                 item_name[strlen(item_name)-1] =0;
    /*The end of a string is represented by a 0 character setting
    a character in a string to 0 moves the end of the string*/                          
                                 index_return =search_name(items,item_name);
                                 if(index_return <0)
                                 {
                                   printf("NOT FOUND!");
                                   break;
                                 }
                                 display_record(items[index_return],index_return);
                                 calculate_change(items[index_return],index_return);
                                 break;
                              }
                              
                         case 4:                          
                              
                                 printf("exting\n");
                                 break;
                                 
                         default:printf("invalid choice, please try again\n\n");
                                 break;
                                 }
                         system("pause");
                         system("cls");
                         }while(menu_code!= 4);
                         
    
    }

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    6
    the above program has a module called search_colour when that module was added is where i started expiriencing the error which said invalid error. This error occurs after the authentication. when the program enters into the switch statements no matter which case statement i select it gives me invalid entry

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Use // to remove the call to your functions one by one, and to your blocks of code, until you find the culprit.

    Naturally, start with the most likely places, first. The bug can run from you, but it can't "hide". Stay positive, and keep narrowing down the list of suspects, until you find it.

    Sprinkling some printf()'s of the variables around, is another good idea.

    Nobody knows your code better than you do.

    What you should have done was code a little, AND THEN TEST THE NEW CODE, then code some more, AND THEN TEST IT.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    First of all, your indentation is poor.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define num_shoes 10
    
    typedef struct
    {
      int code;
      char name[80];
      float price;
      char colour [10];
    }record;
    
    int authentication (int tries)
    {
      char comparison[20],junk[80];
      char username [20]="";
      printf("please enter a valid username. (%d tries left)>",3-tries);
      scanf("%s",username);
      getchar();
      FILE * memberfile =fopen("Memberfile.txt","r");
      for (;memberfile != NULL && !feof (memberfile);)
      {
        comparison[0]=0;
        fscanf(memberfile,"%s",comparison);
        if(strcmp(comparison,username)==0)
        {
          fclose(memberfile);
          return 1;
        }  
        else fgets(junk,80,memberfile);/*reads any remaining characters 
                        on that line and goes down to the new line*/ 
      }
      return 0;        
    }                                                                          
    
    int search_code (record array [] ,int seeked)
    {
      int index =0;
      for (index =0; index < num_shoes; index++)
      {
        if (!array[index].name[0])
        continue;/* if the first character of the name is 0 (no name)
                  then continue forward and skip the comparison. repeat the loop*/
        if (array[index].code ==seeked)
        return index;
      }
      return -1;
    }
    /*the following will search the array for an item using the name as the search field
    if the item is not found it returns -1*/
    
    int search_colour (record array[],char colour[])
    {
      for (int index=0; index<num_shoes;index++)
      {
        if (strcmp (colour,array[index].colour)==0)
        return index;
      }
      return -1;
    }
    
    int search_name (record array[],char name[])
    {
      for (int index =0; index<num_shoes;index++) 
      {
        if (strcasecmp (name,array[index].name)==0)
        return index;
      }
      return -1;
    }
    
    float calculate_change (record item, int index)
    {
      int number_of_shoes;
      float amount_of_money;
      printf("\nhow many items do you want?");
      scanf("%d",&number_of_shoes);getchar();
      printf("cost : $%0.2f\n",item.price*number_of_shoes);
      printf("\n how much money are you paying?");
      scanf("%f",&amount_of_money);getchar();
      printf("\n Your change is :$%.2f\n",amount_of_money-(item.price*number_of_shoes));
    
    }
    
    void display_record (record item, int index)
    {
      int i;
      printf("%-4d %20s\t",item.code,item.name);
      printf("%-4.f\t",item.price);
      printf("%-4d\t",item.colour);
      printf("\n");
      
    }
    
    int main (void)
    {
      int i, j,number_of_items;
      float amount_of_money;
      record items [num_shoes] ={0};//initialise all locations to zero
      char junk;
      int menu_code;
    
      for (j=0; j<3 &&!authentication(j);j++);/*this loops the authentication of the 
                                            user and gives him 5 triesto enter a valid      
                                            user name*/
      if (j==3)                              
      {
        printf("you have been booted from the system please restart\n");
        getchar();
        return -1;
      }
      else printf("welcome to the system\n");
    
      FILE * f =fopen("shoes.txt","r");
      if(!f)
      {
        printf("the file could not be found, create a file\n");
        getchar();
        return 1;//in the main function this means there was an error
      }
      for (i=0; i<num_shoes &&!feof(f);i++);
      {
        fscanf(f,"%d",&items[i].code);
        fscanf(f,"%f",&items[i].price);
        fscanf(f,"%s",items[i].colour);
        /*the fscanfs above will leave a single space on the line, just like a getchar()
          used after a scanf, afgetc must be used here to remove the space otherwise the 
          name read from the file will have a space at the front of it and the program will
          not find the name sought*/     
        fgetc(f);
        fgets(items[i].name,80,f);  
        /*the above line will pick up a maximum of 80 characters from the file, stopping 
          only when 80 chractersare picked up OR a newline character is picked up. The newline 
          remains in the item[i].name string, and must be removed*/          
        items[i].name [strlen(items[i].name) -1] =0;
        /*the line above will use the index 'strlen(items[i].name)' (the length of the name)
          minus ONE space,which would be the second last charcter,and sets the end of the string 
          to that new point,effectively cutting ogg the last character from it*/
      }
      fclose(f);
    
      do
      {
        fflush(stdin);/*clear the input buffer BEFORE reading,just in case 
                              there'sanything there left over from the previous run*/
        
        printf("\n\n1 - search on code \n2 -search on colour \n3 - search on name \n4 - finish \n\n>");
        getchar();
        switch (menu_code)
        {
        case 1:
          {
            int shoe_code, index_return;
            printf("which shoe code?>");
            scanf("%d",&shoe_code);
            getchar();
            index_return = search_code(items,shoe_code);
            if (index_return <0)
            {
              printf("NOT FOUND!");
              break;
            }
            display_record(items[index_return],index_return);
            calculate_change(items[index_return],index_return);
            break;
          }   
        case 2:
          {
            int index_return;
            char shoe_colour[10]="";
            printf("which shoe colour?>");
            scanf("%s",shoe_colour);
            index_return=search_name(items,shoe_colour);
            if (index_return<0)
            {
              printf("NOT FOUND!");
              break;
            }
            display_record(items[index_return],index_return);
            calculate_change(items[index_return],index_return);
            break;
          }
        case 3:
          {
            int index_return=0;
            char item_name[100] ="";
            printf("which item name");
            /*A simple scanf will not work here because the names have spaces,therefore we
              will use an fgets() with the file as 'stdin'. This represents standard input
              and is representative of the console. The line below means get a maximum of 80 
              characters from the user and stores it in 'item_name' like the previous fgets,
              the end must be cut off.*/
            fgets(item_name,80,stdin);
            item_name[strlen(item_name)-1] =0;
            /*The end of a string is represented by a 0 character setting
              a character in a string to 0 moves the end of the string*/                          
            index_return =search_name(items,item_name);
            if(index_return <0)
            {
              printf("NOT FOUND!");
              break;
            }
            display_record(items[index_return],index_return);
            calculate_change(items[index_return],index_return);
            break;
          }      
        case 4:                            
          printf("exting\n");
          break;
        default:printf("invalid choice, please try again\n\n");
          break;
        }
        system("pause");
        system("cls");
      }while(menu_code!= 4);
    }
    Decent indentation will spot lots of bugs before you even press compile.

    2. This isn't C code (well, it's C99 code, not C89 code).
    You have mixed declarations and statements, like
    FILE * memberfile =fopen("Memberfile.txt","r");
    appears after statements.

    Likewise,
    for (int index=0; index<num_shoes;index++)
    this kind of declaration is also a new C99 feature.

    Maybe it's OK for you (or maybe you're using a C++ compiler and not realising it).
    But C89 is still the most portable version of C.

    3. for (i=0; i<num_shoes &&!feof(f);i++);
    Watch the ; at the end.


    And read this before writing your next program.
    A development process
    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.

  8. #8
    Registered User
    Join Date
    Jan 2010
    Posts
    6
    well first of all i am using dev C++ a frend of mine told me that its a C++ program but were using C programming in it. there was nothing wrong with that for loop statement since when i took out the ; from the for (i=0; i<num_shoes &&!feof(f);i++) statement the program did the same thing. it is bringing up the menu for the case statement and when i try to enter to enter a number it keeps saying invalid choice. Maybe it has something to do with the way i read in the colour because as u can see i took some elaborate way to read in the name field from the textfile mainly this statement here

    fgetc(f);
    fgets(items[i].name,80,f);

    items[i].name [strlen(items[i].name) -1] =0;
    where as for the other string variable i simply read it in using this statement

    fscanf(f,"%s",items[i].colour);

    could that have anything to do with the problems i am having or is it my case statements

    which are
    Code:
    switch (menu_code)
                     {
                        case 1:
                             {
                                int shoe_code, index_return;
                                printf("which shoe code?>");
                                scanf("%d",&shoe_code);
                                getchar();
                                index_return = search_code(items,shoe_code);
                                if (index_return <0)
                                   {
                                       printf("NOT FOUND!");
                                       break;
                                   }
                                 display_record(items[index_return],index_return);
                                 calculate_change(items[index_return],index_return);
                                 break;
                                } 
                         
                         case 2:
                              {
                                int index_return;
                                char shoe_colour[10]="";
                                printf("which shoe colour?>");
                                scanf("%s",shoe_colour);
                                index_return=search_name(items,shoe_colour);
                                if (index_return<0)
                                   {
                                      printf("NOT FOUND!");
                                      break;
                                   }
                                display_record(items[index_return],index_return);
                                calculate_change(items[index_return],index_return);
                                break;
                                }
                         
                         
                         case 3:
                              {
                                 int index_return=0;
                                 char item_name[100] ="";
                                 printf("which item name");
    /*A simple scanf will not work here because the names have spaces,therefore we
    will use an fgets() with the file as 'stdin'. This represents standard input
    and is representative of the console. The line below means get a maximum of 80 
    characters from the user and stores it in 'item_name' like the previous fgets,
    the end must be cut off.*/
                                 fgets(item_name,80,stdin);
                                 item_name[strlen(item_name)-1] =0;
    /*The end of a string is represented by a 0 character setting
    a character in a string to 0 moves the end of the string*/                          
                                 index_return =search_name(items,item_name);
                                 if(index_return <0)
                                 {
                                   printf("NOT FOUND!");
                                   break;
                                 }
                                 display_record(items[index_return],index_return);
                                 calculate_change(items[index_return],index_return);
                                 break;
                              }
                              
                         case 4:                          
                              
                                 printf("exting\n");
                                 break;
                                 
                         default:printf("invalid choice, please try again\n\n");
                                 break;
                                 }

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The problem is that no one can run your program, unless they have a C99 compiler. Very few people have one of those.

    I strongly suggest you use C89 (standard) C for your programs.

    You have no way to step through the program and watch the variables?

  10. #10
    Registered User
    Join Date
    Jan 2010
    Posts
    6
    Quote Originally Posted by Adak View Post
    The problem is that no one can run your program, unless they have a C99 compiler. Very few people have one of those.

    I strongly suggest you use C89 (standard) C for your programs.

    You have no way to step through the program and watch the variables?
    No i have no way to do so. Unless u mean the compiling log which is always at the bottom. that only gives u a list of ambiguous issues with the program though. Im a student btw this isnt really my preference program it was the one i was given to use :/. Do you think i should post my problem in the C++ section?

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    The problem is a lack of consistency.
    You have in one short section of code calls to
    - getchar()
    - scanf()
    - fgets()

    The result is you really don't know what state the input stream is in, and so every so often an unexpected character is read and you get some unexpected result.
    The answer would be to use fgets() for ALL input, then use sscanf() where appropriate (in places where you use scanf directly).

    > it is bringing up the menu for the case statement and when i try to enter to enter a number it keeps saying invalid choice.
    So add some debug...
    Code:
    default:
      printf("invalid choice, please try again\n\n");
      printf("Bad menu code=%d\n", menu_code);
    My guess is the result will be 10 most of the time, indicating a trailing newline has not been processed by a previous menu option.

    > Do you think i should post my problem in the C++ section?
    There is nothing wrong with your code per se, it's just that it is really important that you understand where all the boundaries are.
    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. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Sugguestion on choosing my modules
    By ssharish2005 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-27-2007, 05:44 PM
  3. Multiple Modules
    By rwmarsh in forum C++ Programming
    Replies: 6
    Last Post: 02-18-2006, 04:34 PM
  4. Problems with modules
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2005, 08:56 PM
  5. Problems trying to install additional DIMM modules :(
    By Gades in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 05-28-2002, 02:45 AM