Code:
int main ( ) {
char cmd[100] = "this is a test";
char cmd_words[20][100];
int i,nwords=0,nword_chars=0;
for ( i = 0 ; i < strlen(cmd) ; i++ ) {
if ( cmd[i] != ' ' ) {
// copy the char, and keep the word a proper string (the \0)
cmd_words[nwords][nword_chars++] = cmd[i];
cmd_words[nwords][nword_chars] = '\0';
} else {
nword_chars = 0; // start of...
nwords++; // the next word
}
}
// trap last word not ending in a space
if ( nword_chars != 0 ) nwords++;
for ( i = 0 ; i < nwords ; i++ ) {
printf( "Word %d is %s\n", i, cmd_words[i] );
}
return 0;
}
> char cmdarg[1000][1000];
Bear in mind that this is almost 1MB in size - you don't want too many of these lying around.