Tehreem Tehreem - 6 months ago 75
C Question

Why is strtok printing only first word?

I am using strtok for converting string into individual words. I have done the following:

int main() {
char target[100];
char *t;
t = strtok(target," ");
while (t!= NULL)
printf("<<%s>>\n", t);
t = strtok (NULL, " ");
return 0;

The input is a string such as 'this is a string', the output I am getting is


The way you have written scanf it will accept string till white space only


SO You need to change the way you take input from console