user account name input

Discussion in 'C' started by Aigolek, Jul 21, 2010.

  1. Aigolek

    Aigolek New Member

    Joined:
    Apr 14, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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 :)
     
  2. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    remove the break;
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice