-
Gets problem I think
How can I make that the do-while keeps repeating while the user hasnt entered anything?? I mean, if when asked to enter your name you just press ENTER then the do-while repeats... I have this code but it doesnt work!!
Can you help me?
Code:
void pidenombre(void)
{
do{
printf("Your name?");
gets(nombre);
}while(nombre=="\0");
}
-
You should be trying to capture a new line not a null terminator. so use '\n' instead of '\0'.
-
>
}while(nombre=="\0");
Is wrong. You are trying to compare strings but instead are comparing their addresses. Try this instead:
Code:
}while(nombre[0]=='\0'); /* Check the single quote ' */
OR
Code:
}while(!strlen(nombre));
>You should be trying to capture a new line not a null terminator. so use '\n' instead of '\0'.
gets() breaks when it encounters a '\n', which is not returned in the string, so, checking for '\n' is not going to help you
-
You all have overlooked the most obvious flaw: they're actually using gets! Never use gets. Use fgets instead. It's safer.
Quzah.