1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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 New Member

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

Share This Page