C++ string切割,分解字符串,C 库函数 - strtok()

2023-05-16

声明

下面是 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\n", token ); 
         token = strtok(NULL, s); } return(0); 
    }
}

让我们编译并运行上面的程序,这将产生以下结果:


 This is 
 www.runoob.com 
 website  

转载自https://www.runoob.com/cprogramming/c-function-strtok.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C++ string切割,分解字符串,C 库函数 - strtok() 的相关文章

  • 查看vs支持的c#语言版本/查看.NetCore版本/更改c#语言版本

    1 查看vs支持的c 版本 注意语言版本控制 官网解释 Windows 10 选择 开始 键盘上的 Windows 徽标键 并滚动到字母 V 展开 Visual Studio 2019 文件夹 选择 VS 2019 开发人员命令提示 xff
  • Yum项目上线实战(网站运维)

    项目上线 一 编译安装与卸载Nginx二 关于LAMP三 LAMP环境部署 一 编译安装与卸载Nginx Nginx xff1a 是一款比较流行的web服务器软件 xff0c 类似于Apache 1 安装nginx 下载nginx ngin
  • elment ui 全部报错,参数不能赋给类型“App<any> ,怀疑是插件更新的原因

    elment组件全部报错 xff0c 的参数不能赋给类型 App lt any gt amp xff0c 有一样的情况的吗 xff0c 目前怀疑是插件更新的原因
  • mybatis-plus-boot-starter 引用不了包BaseMapper

    我的解决办法是 xff1a 调整版本号到3 2 0 lt dependency gt lt groupId gt com baomidou lt groupId gt lt artifactId gt mybatis plus boot s
  • Unrecognized option: --Xmx5120m

    Container exited with a non zero exit code 1 Error file prelaunch err Last 4096 bytes of prelaunch err Last 4096 bytes o
  • 廖雪峰Python教程之mapreduce

    1 map 函数 map 函数接收两个参数 xff0c 一个是函数 xff0c 一个是Iterable xff0c map将传入的函数依次作用到序列的每个元素 xff0c 并把结果作为新的Iterator返回 def f x return
  • 正则基础知识

    正则 RegExp xff1a 由相关元字符和修饰符组成的一个规则 xff0c 匹配 验证和捕获 xff08 只用来处理字符串 xff09 可以理解为两个斜杠中间包含一些内容就是正则 元字符 xff1a 元字符 两个斜杠之间包起来的内容 正
  • The packaging for this project did not assign a file to the build artifact 问题解决

    1 问题出现场景 新建一个Java工程 xff0c 添加testng依赖文件 xff0c 准备使用mvn install安装testng工具时 xff0c 点击如下图1 xff0c 发生以下报错信息图2 xff0c The packagin
  • vscode连接服务器免密码登录

    在windows环境下 xff0c 有时候需要用到linux平台开发 xff0c 如果用Ubuntu虚拟机的话 xff0c 用起来很不习惯 xff0c 不方便切换到windows界面 xff0c 可以把代码放到服务器上 xff0c 用vs
  • kubectl安装无法连接packages.cloud.google.com

    1 问题描述 Err 4 https packages cloud google com apt kubernetes xenial InRelease Could not connect to packages cloud google
  • Centos8-stream安装PostgreSQL13

    一 安装postgresql13 server yum span class token function install span y https download postgresql org pub repos yum reporpm
  • ttf文件结构解析

    TrueType字体通常包含在单个TrueType字体文件中 xff0c 其文件后缀为 TTF OpenType字体是以类似 于TrueType字体的格式编码的POSTSCRIPT字体 OPENTYPE字体使用 OTF文件后缀 OPENTY
  • centos卸载软件三种方式

    1 我们来卸载用yum安装的软件 xff1a yum remove 软件名字 xff1b 2 如果是用rpm包安装的软件呢 xff0c 则使用如图命令进行卸载 xff1b rpm e 软件名 xff1b 3 如果是用tar包安装的软件呢 x
  • Pycharm设置http代理

    1 Pycharm设置 2 urllib下载数据配置 span class token keyword from span urllib span class token punctuation span error span class
  • Docker 配置网络代理

    有时因为网络原因 xff0c 比如公司 NAT xff0c 或其它啥的 xff0c 需要使用代理 Docker 的代理配置 xff0c 略显复杂 xff0c 因为有三种场景 但基本原理都是一致的 xff0c 都是利用 Linux 的 htt
  • 安装 OpenVPN 客户端

    安装 OpenVPN 客户端 yum y span class token function install span epel release yum y span class token function install span op
  • 字符串-字符串匹配

    Leetcode 28题 1 题目描述 Given two strings needle and haystack return the index of the first occurrence of needle in haystack
  • pip无法安装包到新创建的虚拟环境下面,安装包冲突

    第1步 xff1a 查看安装包的路径 span class token punctuation span label studio span class token punctuation span user 64 master pytho
  • 数组-二分查找

    1 Search a 2D Matrix 1 1 题目描述 span class token comment You are given an m x n integer matrix matrix with the following t
  • 渗透测试工具学习笔记(1)——netcat(nc)

    v 显示详细输出内容 n 跟IP地址 xff0c 不进行DNS解析 l 打开一个listen端口 p 端口号 q n 当标准输出完成后延迟n秒断开 z 扫描模式 xff0c 不做I O操作 1 telnet banner nc vn ip地

随机推荐