So, I have the following code:
void main(int argc, char **argv)
{
int loggedIn=0;
char *currentCommand;
while (!loggedIn)
{
printf("Enter your command:");
scanf("%s",currentCommand);
printf("\n%s\n",currentCommand);
}
}
The problem scanf()works well for the first time, then reading starts (null), and the output will be Enter your command: (null)in an infinite loop.
I want to enter more commands and stop when I change the loggedIn value, but as soon as I enter one command, it starts to print Enter your command: (null)by default.
source
share