字符串分隔 查找函数

来源:互联网 发布:ubuntu 读取u盘 编辑:程序博客网 时间:2024/05/16 08:23
 原型: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


原创粉丝点击