Monday, May 24, 2010

Strtok() prob in c?

#include %26lt;stdio.h%26gt;


#include %26lt;string.h%26gt;





int main ()


{


char num[] ="1.00:2.00:3.00";


char *ch;


char r[100];


printf ("split \"%s\":\n",num);


ch = strtok (num,":");


while (ch != NULL)


{


i = 0;


printf ("%s\n",ch);


ch = %26amp;r[i];


ch = strtok (NULL, ":");


i ++;


}


return 0;


}








--%26gt; here is my strtok code, but it doesn't work.





how can i copy the values of the pointer ch into a char array r? thanks.

Strtok() prob in c?
1. need to add "int i = 0;" at the top and remove "i = 0;".


2. the printf is working fine.


3. strcpy(%26amp;r[i],ch); i += strlen(ch) + 1; instead of the last 3 lines in the llop


No comments:

Post a Comment