zoukankan      html  css  js  c++  java
  • strtok():字符串分割

    描述

    C 库函数 char *strtok(char *str, const char *delim) 分解字符串 str 为一组字符串,delim 为分隔符。

    声明

    下面是 strtok() 函数的声明。

    char *strtok(char *str, const char *delim)

    参数

    • str -- 要被分解成一组小字符串的字符串。
    • delim -- 包含分隔符的 C 字符串。

    返回值

    该函数返回被分解的第一个子字符串,如果没有可检索的字符串,则返回一个空指针。

    实例

    下面的实例演示了 strtok() 函数的用法。

    #include <string.h>
    #include <stdio.h>
     
    int main () {
       char str[80] = "This is - www.runoob.com - website";
       const char s[2] = "-";
       char *token;
       
       /* 获取第一个子字符串 */
       token = strtok(str, s);
       
       /* 继续获取其他的子字符串 */
       while( token != NULL ) {
          printf( "%s
    ", token );
        
          token = strtok(NULL, s);
       }
       
       return(0);
    }

    参考资料:

    菜鸟教程

  • 相关阅读:
    LDA的整体流程
    java中字符串的用法
    verification Code
    properties
    Hash
    substring的问题
    LDA和PLSA的区别
    Step By Step(Lua环境)
    Step By Step(Lua调用C函数)
    Step By Step(Lua弱引用table)
  • 原文地址:https://www.cnblogs.com/xumaomao/p/11990593.html
Copyright © 2011-2022 走看看