This line:
scanf("%[^\n]", command);
Is reading characters up to but not including a newline and putting them into command
. The newline is left in the input buffer.
When you execute that statement the next time around the loop, it does the same thing ... except that the first character it will encounter will be the same newline that it saw last time. Net result: it sets command
to an empty string, and leaves the newline for the next call. And so on.
You need to consume that newline.