字符串分隔 查找函数

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


    char s[]="ab-cd : ef;gh :i-jkl;m nop;qrs-tu: vwx-y;z";  
    char *delim=":";  
    char *p;  


    printf("%s\r\n",strtok(s,delim));  
	
    while((p=strtok(NULL,delim)))  
        printf("%s\n",p);  


	system("pause");
}  
 
 原型:extern char *strchr(char *s,char c);
        
  用法:#include <string.h>
  
  功能:查找字符串s中首次出现字符c的位置
  
  说明:返回首次出现c的位置的指针,如果s中不存在c则返回NULL。
  
  举例:


      // strchr.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char *s="Golden Global View";
        char *p;
        
        clrscr();
        
        strchr(s,'V');
        if(p)
          printf("%s",p);
        else
          printf("Not Found!");

        getchar();
        return 0;
      }
      
 原型:extern char *strdup(char *s);
        
  用法:#include <string.h>
  
  功能:复制字符串s
  
  说明:返回指向被复制的字符串的指针,所需空间由malloc()分配且可以由free()释放。
  
  举例:


      // strdup.c
      
      #include <syslib.h>
      #include <string.h>

      main()
      {
        char *s="Golden Global View";
        char *d;
        
        clrscr();
        
        d=strdup(s);
        printf("%s",d);

        getchar();
        return 0;
      }
      
  原型:extern int stricmp(char *s1,char * s2);
        
  用法:#include <string.h>
  
  功能:比较字符串s1和s2,但不区分字母的大小写。
  
  说明:strcmpi是到stricmp的宏定义,实际未提供此函数。
        当s1<s2时,返回值<0
        当s1=s2时,返回值=0
        当s1>s2时,返回值>0


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值