阅读:2217回复:3
标准c,strtok()用法?
各位高手,兄弟现在有难:标准c中函数strtok();谁对此函数有准确地使用的例子,兄弟我现在没足够资料,时间紧迫,现在已经零晨了,大家帮忙详细解释一下,并带上编译通过的例子,好吗?
现再次谢过大家了! |
|
沙发#
发布于:2002-10-21 07:55
你man一下嘛
man strok 这用来反字符串拆开的 比如 s=\"1234\'567\'abc\'\" strok(s,\'\\\'\') 然后再调用两次strok(,\'\\\'\') 就可以得到所有的串了 |
|
|
板凳#
发布于:2002-10-21 09:54
//希望有助
/* STRTOK.C: In this program, a loop uses strtok * to print all the tokens (separated by commas * or blanks) in the string named \"string\". */ #include <string.h> #include <stdio.h> char string[] = \"A string\\tof ,,tokens\\nand some more tokens\"; char seps[] = \" ,\\t\\n\"; char *token; void main( void ) { printf( \"%s\\n\\nTokens:\\n\", string ); /* Establish string and get the first token: */ token = strtok( string, seps ); while( token != NULL ) { /* While there are tokens in \"string\" */ printf( \" %s\\n\", token ); /* Get next token: */ token = strtok( NULL, seps ); } } Output A string of ,,tokens and some more tokens Tokens: A string of tokens and some more tokens |
|
地板#
发布于:2002-10-23 00:07
问题解决了(将用户输入的串,分割成字,后将每个字分别放入指针数组):(类型转换:)部分代码如下:
感谢各位大侠! char *get_word[5],*substring; char string[20],seps\"/,-\"; ... main(){ ... while(1){ get(string); substring=(char *)strtok(string,seps); while(substring!=NULL){ get_word[i++]=substring; substring=(char)strtok(NULL,seps) } } ... } |
|