I want to have an infinite loop getting command each loop,
and this is my code
while ( 1 )
{
char * command[100];
printf("---| ");
scanf( "%[^\n]",command);
printf("%s\n",command);
}
for some reason it only inputs once and the loop doesnt terminate with asking the input.
what did i do wrong here?
The definition should be
char command[100];
And not char *command[100] - this is a array of 100 char pointers.
Also scanf() is not easy to use, I would use fgets(command, sizeof(command), stdin);
and then remove the newline.
while ( 1 )
{
char command[100];
printf("---| ");
scanf( "%s", command);
printf("%s\n",command);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With