Don't use scanf - its tricky to stop it reading past a newline
Code:
#include <stdio.h>
int main ( ) {
char buff[BUFSIZ];
while ( fgets(buff,BUFSIZ,stdin) != NULL ) {
char cmd[100], param[100];
int res = sscanf( buff, "%s %[^\n]", cmd, param );
if ( res == 1 ) {
printf( "command '%s' with no arg\n", cmd );
} else
if ( res == 2 ) {
printf( "command '%s' with arg '%s'\n", cmd, param );
}
}
return 0;
}
Gets you
hello
command 'hello' with no arg
hello world how are you
command 'hello' with arg 'world how are you'