3

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?

JaemyeongEo
  • 183
  • 1
  • 3
  • 14

1 Answers1

2

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);
}
suspectus
  • 16,548
  • 8
  • 49
  • 57