hey i am trying to use the strtok function in C with " " as a delimiter and for some reason it does not work. can some one please tell me how to parse using strtok with a space as a delimiter thanks in advance
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Stolen (and slightly modified) from here.
/* strtok example */ #include <stdio.h> #include <string.h> int main () { char str[] ="- This, a sample string."; char * pch; printf ("Splitting string \"%s\" into tokens:\n",str); pch = strtok (str," "); while (pch != NULL) { printf ("%s\n",pch); pch = strtok (NULL, " "); } return 0; }
回答2:
Use tab "\t" or use both " \t" ie. space and tab both...see if it works