I am getting and displaying names, and stop the program when I type enter key. At the below code I get the correctly result (I know "gets" is deprecated):
#include <stdio.h>
main()
{
char name[50];
while(1)
{
printf("Name: ");
scanf("%s", name);
if(name[0]=='\0')
break;
else
printf("Name entered: %s\n", name);
}
}
But when I try to use scanf:
printf("Nome: ");
scanf("%s", nome);
The condition name[0]=='\0'
never is true this time. Why? The '\0'
works differently in these functions?