Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   user account name input (http://www.go4expert.com/forums/user-account-input-t22778/)

Aigolek 21Jul2010 23:50

user account name input
 
Hi, everybody! I want to ask one question, i have piece of code where i am trying to validate user account name input, and it seems working, despite of one thing if I put non existing name, the programs continue work, however it should be terminated. The code of problem is here:
Code:

printf("\nEnter Account Name: ");
    fflush(stdin);
    fgets(name, sizeof(name), stdin);       
    int len = strlen(name);
    if(name[len-1] == '\n')       
    name[len-1] = '\0';
    while (fread(buffer, sizeof(account), 1, members))
        {
                if(strcmp(buffer->acc_name, name)==0){
              fgetpos(members,&here);
              printf ("\nAccept! Account exists.");
              break;
              fsetpos(members, &here);
        }
        else{
              if (!feof(members))continue;
              else
            {
              break; printf("Account does not exist");
              exit(1);}
              }
 
        }

when i debugging the code with non exisistng account name, it missing this part,
Code:

else
            {
              break; printf("Account does not exist");
              exit(1);}
              }

And i really cannot understand why it doesn't go there.I've tried to change the loop structure, but it doesn't work. I really cannot get what it can be. Thank you very much for help :)

virxen 22Jul2010 03:51

Re: user account name input
 
remove the break;


All times are GMT +5.5. The time now is 11:50.