Okay, I changed your code into a complete program, cf:
#include <stdio.h>
#include <string.h>
int main() {
char buffer[256];
char *token;
int count = 0;
fgets(buffer, 256, stdin);
token=strtok(buffer," \n\t()<>|&;");
while(token!=NULL) {
printf("%s\n",token);
count++;
token = strtok(NULL," \n\t()<>|&;");
}
return 0;
}
when I run it in it's original form it works
bash $ ./a.out
the quick brown fox
thequickbrownfoxbash $
Although of course there are no spaces or newlines. When I add the \n
, (as in code above) I get
bash $ ./a.out
the quick brown fox
the
quick
brown
fox
bash $
Now, note that I had to remove your back-tick (I assume it was a typo) and I had to declare your count
variable, but given that it works.
From this I deduce that you probably have code around the fragment you showed us that's at fault.