Chinaunix首页 | 论坛 | 博客
  • 博客访问: 685053
  • 博文数量: 108
  • 博客积分: 3236
  • 博客等级: 中校
  • 技术积分: 906
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-04 21:23
文章分类

全部博文(108)

文章存档

2011年(33)

2010年(75)

我的朋友

分类: C/C++

2010-12-23 12:27:14

strsep()

#include
#include
#include

int main(void)
{
char   ptr[]={ "abcdefghijklmnopqrstuvwxyz "};
char   *p,*str= "m ";
p=ptr;
printf( "%s\n ",strsep(&p,str));
printf( "%s\n ",p);
str= "s ";
printf( "%s\n ",strsep(&p,str));
printf( "%s\n ",p);

    return 0;
}


运行结果
[root@localhost strsep]# gcc -o strsep strsep.c
[root@localhost strsep]# ./strsep
abcdefghijkl
nopqrstuvwxyz
nopqr
tuvwxyz
[root@localhost strsep]#

strtok
原型:extern char *strtok(char *s, char *delim);     
用法:#include   
功能:分解字符串为一组标记串。s为要分解的字符串,delim为分隔符字符串。  
说明:首次调用时,s必须指向要分解的字符串,随后调用要把s设成NULL。
        strtok在s中查找包含在delim中的字符并用NULL('\0')来替换,直到找遍整个字符串。
        返回指向下一个标记串。当没有标记串时则返回空字符NULL。

举例:
      // strtok.c     
      #include
      #include
      #include

      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;
      }

阅读(988) | 评论(0) | 转发(0) |
0

上一篇:他山之石

下一篇:getopt的用法

给主人留下些什么吧!~~