/* strtok函数的使用 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // 函数原型:
// char *strtok(char *str, const char *delim) // 参数:
// str -- 要被分解成一组小字符串的字符串
// delim -- 包含分隔符的 C 字符串 // 返回值
// 该函数返回被分解的第一个子字符串,如果没有可检索的字符串,则返回一个空指针 int main() {
  char testString[] = " tong yi shu ";
  const char delim[] = " ";
  //不同的delim对应的分解结果如下
  // tong -- 4
  // yi -- 2
  // shu -- 3   //const char delim[] = "oh";
  // t -- 6
  //ng yi s -- 12
  //u -- 4   char* subStr = strtok(testString, delim);
  while (subStr != NULL) {
    printf("%s -- %d\n", subStr, strlen(subStr));
    subStr = strtok(NULL, delim);
  }
  return ;
}

strtok的使用的更多相关文章

  1. strsep和strtok_r替代strtok

    char *strtok(char *str, const char *delim) 会修改数据源.外部加锁才线程安全(strtok执行结束再解锁执行另一个strtok循环知道工作完成) 主要是以互斥 ...

  2. loadrunner中切割strtok字符串

    http://blog.sina.com.cn/s/blog_7ee076050102vamg.html http://www.cnblogs.com/lixiaohui-ambition/archi ...

  3. strtok&strsep

    strtok,strtok_r,strsep--extract tokens from strings Tje strsep() function was introduced as a replac ...

  4. 字符串分割函数 STRTOK & STRTOK_R (转)

    1.一个应用实例 网络上一个比较经典的例子是将字符串切分,存入结构体中.如,现有结构体 typedef struct person{     char name[25];     char sex[1 ...

  5. strtok和strtok_r

    1.strtok()函数的用法 函数原型:char *strtok(char *s, const char *delim); Function:分解字符串为一组字符串.s为要分解的字符串,delim为 ...

  6. 浅谈strtok

    原型:char *strtok(char *s, char *delim); 功能:分解字符串为一组标记串.s为要分解的字符串,delim为分隔符字符串. 说明:首次调用时,s必须指向要分解的字符串, ...

  7. 函数strtok

    char* strtok(char *str, const char*delim) char *strtok_r(char *str, const char *delim, char **savept ...

  8. strtok

    1. Int main(void) { char *tmp = NULL; Char *remotebuf=”0\r\n”; tmp = strtok(remotebuf, DELIM);      ...

  9. [转]关于strtok和strtok_r函数的深度研究

    在linux环境下,字符串分割的函数中,大家比较常用的是strtok函数,这个函数用处很大,但也有一些问题,以下将深度挖掘一下这个函数的用法,原理,实现,其次,该函数是不可再入函数,但是在linux ...

  10. hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用

    字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...

随机推荐

  1. python学习笔记:(九)循环(for和while)

    在python中循环包括for和while 1.while循环 while 判断条件: statements ----表示:判断条件为真时执行statements,为假不执行 2.for语句 for ...

  2. 1 Configuring SAP ERP Sales and Distribution -introduction to SAP

    SAP is one of the most popular enterprise resource planning (ERP) solutions inthe world. It offers a ...

  3. Scratch少儿编程系列:(十一)Scratch编程之简单见解

    一.Scratch官网的说明     With Scratch, you can program your own interactive stories, games, and animations ...

  4. appium+python+安卓模拟器环境搭建和启动app实例

    本文主要介绍在windows环境下搭建app自动化测试环境,具体步骤如下: 1.下载安卓sdk,网上很多资源 2.下载并安装安卓模拟器,官网上有 删除bin文件下的adb.exe和nox_adb.ex ...

  5. 第十四周课程总结&&实验总结

    课程总结: 1.Java实现跨平台操作的工具:JDBC. 它的意思是java数据库连接,可以方便的实现多种关系型数据库的统一操作,它由一组用java语句编写的类和接口组成. 2.JDBC驱动分类: J ...

  6. Oracle 查看 impdp 正在执行的内容

    1. 今天进行数据库备份恢复 一直卡住  找了一下 公司另外一个部门的方神提供了一个方法连查看 具体在做什么操作: 2. 现象. impdp 到一个地方直接卡住不动 具体位置 view 这个地方足足卡 ...

  7. 使用rsync在linux(服务端)与windows(客户端)之间同步

    说明: 1.RsyncServer服务端 系统:CentOS 6.8 IP地址:192.168.247.141 2.Rsync客户端 系统:Windows10 实现目的: Rsync客户端同步服务端/ ...

  8. HDU-1204-糖果大战

    题目描述 生日\(Party\)结束的那天晚上,剩下了一些糖果,\(Gandon\)想把所有的都统统拿走,\(Speakless\)于是说:"可以是可以,不过我们来玩\(24\)点,你不是已 ...

  9. 细说vue axios登录请求拦截器

    当我们在做接口请求时,比如判断登录超时时候,通常是接口返回一个特定的错误码,那如果我们每个接口都去判断一个耗时耗力,这个时候我们可以用拦截器去进行统一的http请求拦截. 1.安装配置axios cn ...

  10. day 01 常量 注释 int(整型) 用户交互input 流程控制语句if

    python的编程语言分类(重点) if 3 > 2: 编译型: 将代码一次性全部编译成二进制,然后再执行. 优点:执行效率高. 缺点:开发效率低,不能跨平台. 代表语言:C 解释型: 逐行解释 ...