In C, a char* is merely a pointer to some space in memory, but it doesn't automatically allocate that space in memory. You need malloc() to actually provision some of your computer's memory for your program to use.
char *command = (char*) malloc(20 * sizeof(char)); // Allocates enough memory in the heap for 20 characters.
Don't forget to release that memory when you're done with it when it is allocated in this way:
free(command); // Releases the memory pointed to by 'command'
Of course, there's no reason in your program why you must
allocate memory from the heap. A static allocation on the stack will work just as well, and you won't need to concern yourself with freeing it afterwards:
and does scanf stops when space is encountered?
Yes, according to the scanf() documentation (http://www.cplusplus...y/cstdio/scanf/
s String of characters Any number of non-whitespace characters, stopping at the first whitespace character found. A terminating null character is automatically added at the end of the stored sequence.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid