To store a whole set of words, you need an array of words, or at least an array of pointers pointing to each word.
OP ch is an array of characters, not an array of pointers to characters.
Possible approach:
int main() { char sentence[] = "my name is john"; int i = 0; char * ch[50] = {0}; char * word = strtok(sentence, " "); while ((NULL != word) && (50 > i)) { ch[i] = strdup(word); printf("%s\n", ch[i]); i++; word = strtok(NULL, " ") } return 0; }
source share