Recently in a C language topic need to use the split string, originally wanted to write their own handwriting, it will not be very troublesome, but think of other languages have a split string library function, C language how can not? So, in the online search, sure enough there is such a function, or very useful, in this summary.
1#include <stdio.h>2 3#include <string.h>4 5 intMain ()6 {7 Char inch[10000];8 CharDelims[] =" ";9 Char*result;Ten OneFgetsinch,9995, stdin); A - - theresult = Strtok (inch, delims); - while(Result! =NULL) - { - +printf"%s\n", result); - +result =strtok (NULL, delims); A } at return 0; -}
In the C language manual, it is easy to find out the usage of strtok, one thing to note is that, in addition to the first call, the first parameter is to pass the string to be split, and all other times null.
C-Language split string