C中的strtok (续)
来源:互联网 发布:安阳青峰网络 编辑:程序博客网 时间:2024/06/08 16:03
//----------------------------------------------------
//AUTHOR: lanyang123456
//DATE: 2014-11-09
//---------------------------------------------------#include <stdio.h>#include <string.h>int main(){//char sentence[] = "This is a sentence with 7 tokens";char sentence[] = "first,second.three four,five.";printf("The string to be tokenized is:%s\n", sentence);printf("\nThe tokens are:\n");char *tokenPtr = strtok(sentence, " ,.");while(tokenPtr != NULL) {printf("%s\n", tokenPtr);tokenPtr = strtok(NULL," ,.");}printf("After strtok, sentence = %s\n", sentence);return 0;}
$ gcc -o str7 str7.c
$ ./str7
The string to be tokenized is:first,second.three four,five.
The tokens are:
first
second
three
four
five
After strtok, sentence = first
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { char *str1, *str2, *token, *subtoken; char *saveptr1, *saveptr2; int j; if (argc != 4) { fprintf(stderr, "Usage: %s string delim subdelim\n", argv[0]); exit(EXIT_FAILURE); } for (j = 1, str1 = argv[1]; ; j++, str1 = NULL) { token = strtok_r(str1, argv[2], &saveptr1); if (token == NULL) break; printf("%d: %s\n", j, token); for (str2 = token; ; str2 = NULL) { subtoken = strtok_r(str2, argv[3], &saveptr2); if (subtoken == NULL) break; printf(" --> %s\n", subtoken); } } exit(EXIT_SUCCESS); }
$ ./a.out 'a/bbb///cc;xxx:yyy:' ':;' '/'
1: a/bbb///cc
--> a
--> bbb
--> cc
2: xxx
--> xxx
3: yyy
--> yyy
参考man page
0 0
- C中的strtok (续)
- c中的strtok函数
- C中的strtok
- C函数库中的strtok实现
- strtok函数(C)
- C/C++中的Split函数—strtok
- strtok.c
- c strtok()
- 操作系统大型实验进展(14)-----strtok函数在C和C++语言中的使用
- C库源代码实现: C/C++中的Split函数strtok
- C字符串分割(strtok和strtok_r)
- (standard c libraries translation )strtok
- c语言字符串分割函数(strtok())
- C function strtok()
- C 字符串分隔 strtok
- C函数Strtok详解
- linux c strtok
- C strtok strtok_r
- 总账追朔各模块SQL
- Java 内存区域和GC机制
- jsp中的注释
- Android自动化测试中AccessibilityService获取控件信息(1)
- static_cast, dynamic_cast, const_cast探讨
- C中的strtok (续)
- lucene学习记录(一)--lucene demo的学习
- java设计模式-单例模式
- 90% of python in 90 minutes
- UVA 1584
- 基于express框架的应用程序骨架生成器介绍
- Google 2015 校招第四轮在线技术笔试 解题报告
- 资源链接
- 关于Java中使用JDBC连接查询数据表中的数据