unusual behaviour by GETS function
The first gets function gets skiped but the remaining get functions work, that is the control just moves on to the next line. WHy is this happenning
Code:
void add_address(void)
{
int slot;
slot = -1;
slot = find_free();
if( slot == -1 )
{
printf("\nData base full!!!! Cannot add record");
return;
}
printf("\nAdding record to database at slot number : %d \n", slot);
printf("\nEnter Name : ");
gets(address[slot].name); //<=THIS gets() gets skiped
printf("\nEnter Street : ");
gets(address[slot].street); //BUT this gets() works, why???
printf("\nEnter Citi : ");
gets(address[slot].citi);
printf("\nEnter state : ");
gets(address[slot].state);
printf("\nEnter ZIP : ");
scanf("%u", &address[slot].zip);
return;
}
When I run this program this part of the code
Code:
printf("\nEnter Name : ");
gets(address[slot].name);
gets neglected, control just moves on to the nex line and asks for the input for the next data which is
Code:
printf("\nEnter Street : ");
gets(address[slot].street);
I cannot understand why its not asking for a input for
Code:
printf("\nEnter Name : ");
gets(address[slot].name);
, why is it moving on to next line.
If I replace "gets" with "scanf", then the compiler asks for the input of name but will skip the next gets function.