twzheng's cppblog

『站在风口浪尖紧握住鼠标旋转!』 http://www.cnblogs.com/twzheng

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  136 随笔 :: 78 文章 :: 353 评论 :: 0 Trackbacks
strtok
  原型:extern char *strtok(char *s, char *delim);
                        用法:#include <string.h>
                        功能:分解字符串为一组标记串。s为要分解的字符串,delim为分隔符字符串。
                        说明:首次调用时,s必须指向要分解的字符串,随后调用要把s设成NULL。
                        strtok在s中查找包含在delim中的字符并用NULL('\0')来替换,直到找遍整个字符串。
                        返回指向下一个标记串。当没有标记串时则返回空字符NULL。
                        举例:
                        // strtok.c
                        #include <syslib.h>
                        #include <string.h>
                        #include <stdio.h>
                        main()
                        {
                        char *s="Golden Global View";
                        char *d=" ";
                        char *p;
                        clrscr();
                        p=strtok(s,d);
                        while(p)
                        {
                        printf("%s\n",s);
                        strtok(NULL,d);
                        }
                        getchar();
                        return 0;
                        }
                        相关函数:strcspn , strpbrk
posted on 2007-04-01 18:09 谭文政 阅读(2032) 评论(3)  编辑 收藏 引用 所属分类: C/C++

评论

# re: 字符串函数:strtok(char *s, char *delim) 2008-02-10 22:33
while(p)
{
printf("%s\n",s);
p=strtok(NULL,d);
}
这么明显的错误都看不出来?  回复  更多评论
  

# re: 字符串函数:strtok(char *s, char *delim) 2010-07-07 15:16 vzomik
@啊
应该怎么改??  回复  更多评论
  

# re: 字符串函数:strtok(char *s, char *delim) 2010-07-07 15:22 vzomik
应该
#include <string.h>
#include <stdio.h>
int main(void)
{
char input[16] = "a,b,c,d,e";
char *p;
p = strtok(input, ",");
while (p)
{
printf("%s\n", p);
p = strtok(NULL, ",");
}
return 0;
}  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理