I'm trying to write a function in C that acts like a command prompt. I'm getting a segfault error. My logic of this follows as: getchar() and check if its a space or not. If it's not a space, add the char onto the msg. If it is a space, end the word and add it onto the command array, and get next word. When it gets new line, it ends.
void getCommand(char *command[10]){
char *msg = ""; //Creates ptr
char c;
int length = 0;
while(getchar() != '\n'){ //while char != new line
c = getchar(); // get char
if(c == ' '){ //if char equal space
c = '\0'; //make c equal end of line
msg[length] = c; //add c to the end of line
strcpy(*command, msg); //copy the word into the first part of the array
command++; //increase command array
}
else{ //if word does not equal space
msg[length] = c; //add char to the msg
length++; //increase length by one
}
}
}