strtok with space delimiter [closed]
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this questionhey i am trying to use the strtok function in C with " " as a delimiter and 开发者_如何学JAVAfor 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
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;
}
Use tab "\t" or use both " \t" ie. space and tab both...see if it works
精彩评论