请问strtok函数的功能是什么,参数是什么意思,返回什么结果。因看了帮助不能理解,请各位多多指教。谢谢!

解决方案 »

  1.   

    MSDN里的例子很清楚了/* STRTOK.C: In this program, a loop uses strtok
     * to print all the tokens (separated by commas
     * or blanks) in the string named "string".
     */#include <string.h>
    #include <stdio.h>char string[] = "A string\tof ,,tokens\nand some  more tokens";
    char seps[]   = " ,\t\n";
    char *token;void main( void )
    {
       printf( "%s\n\nTokens:\n", string );
       /* Establish string and get the first token: */
       token = strtok( string, seps );
       while( token != NULL )
       {
          /* While there are tokens in "string" */
          printf( " %s\n", token );
          /* Get next token: */
          token = strtok( NULL, seps );
       }
    }
    OutputA string   of ,,tokens
    and some  more tokensTokens:
     A
     string
     of
     tokens
     and
     some
     more
     tokens
      

  2.   

    这个帮助我看了,就是没能理解是什么意思,不知道是不是这个意思,把str1中的str2去掉。
      

  3.   

    以后面一个str中的为分割符去取字符串
      

  4.   

    那么token = strtok( NULL, seps );怎么理解?还是不明白上面的例子得到的结果?
      

  5.   

    原型:extern char *strtok(char *s, char *delim);
            
      用法:#include <string.h>
      
      功能:分解字符串为一组标记串。s为要分解的字符串,delim为分隔符字符串。
      
      说明:首次调用时,s必须指向要分解的字符串,随后调用要把s设成NULL。
            strtok在s中查找包含在delim中的字符并用NULL('\0')来替换,直到找遍整个字符串。
            返回指向下一个标记串。当没有标记串时则返回空字符NULL。