Hi, I'm writing a small program in C that will read input from the console. Then put it into a char array. After that I need to split the array into words. I'm not sure how to do this. So far I have put the input into a char array. I need to know if there is a way to tokenize based on a blank character. Or any other suggestions on how to handle this problem. Thanks.
sample:
input: this only a test
array: [t,h,i,s, ,i,s, ,o,n,l,y, ,a, ,t,e,s,t,null]
I would like to get a String array [this,is,only,a,test,null]
main() {
char msg[50], ch;
int i = 0;
printf("***Reading words in your input*****\n\n");
printf("Type something terminated by ENTER button\n");
while ((ch = getchar()) != '\n')
msg[i++] = ch;
msg[i] = '\0';
i = 0;
while (msg[i] != '\0')
putchar(msg[i++]);
printf("\n");
}