注意,上面那篇笔记不完全对,原字符串的改动是切分符原位置均更改为 '0',所以内容都还在,可以通过逐个字符打印检验。
#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); } printf(" "); for (int i = 0; i < 34;i++) printf("%c", str[i]); return (0); }
输出:
This is www.runoob.com website This is www.runoob.com website
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.mushiming.com/mjsbk/7596.html