Chinaunix首页 | 论坛 | 博客
  • 博客访问: 32840
  • 博文数量: 27
  • 博客积分: 1080
  • 博客等级: 少尉
  • 技术积分: 220
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-09 10:29
文章分类

全部博文(27)

文章存档

2011年(1)

2010年(15)

2009年(11)

我的朋友

分类: C/C++

2009-12-16 20:25:18

strcat
原型:extern char *strcat(char *dest,char *src);
       
  用法:#include
 
  功能:把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'。
 
  说明:src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串,否则,会用src字符串取代des字符串,直到满足为止。
        返回指向dest的指针。
 
  举例:
      #include
      #include
      main()
      {
        char d[20]="Golden Global";
        char *s=" View";
        strcat(d,s);
        printf("%s",d);
        getchar();
        return 0;
      }
 
 
strcmp
  原型:extern int strcmp(char *s1,char * s2);
        
  用法:#include 
  
  功能:比较字符串s1和s2。
  
  说明:
        当s1s2时,返回值>0
  
  举例:

      // strcmp.c
      
      #include 
      #include 

      main()
      {
        char *s1="Hello, Programmers!";
        char *s2="Hello, programmers!";
        int r;
        
        clrscr();
        
        r=strcmp(s1,s2);
        if(!r)
          printf("s1 and s2 are identical");
        else
        if(r<0)
          printf("s1 less than s2");
        else
          printf("s1 greater than s2");
        

        getchar();
        return 0;
      }
strstr
原型:extern char *strstr(char *haystack, char *needle);
        
  用法:#include 
  
  功能:从字符串haystack中寻找needle第一次出现的位置(不比较结束符NULL)。
  
  说明:返回指向第一次出现needle位置的指针,如果没找到则返回NULL。
  
  举例:      
      #include 
#include
int main(){
    char *s="golden global view";
    char *l="lob";
    char *p;
   
    p=strstr(s,l);
    if(p)
      printf("%s",p);
    else
      printf("not find!");
    system("pause");
    return 0;
    }
//输出:lobal view
阅读(359) | 评论(0) | 转发(0) |
0

上一篇:C深层探索

下一篇:C字符串操作函数

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