background image

函数名:strchr 

 

功 能: 在一个串中查找给定字符的第一个匹配之处\ 

 

用 法:char*strchr(char*str,charc); 
程序例: 

#include<string.h> 
#include<stdio.h> 

intmain(void) 
 { 
      charstring[15]; 
      char*ptr,c='r'; 

      strcpy(string,"Thisisastring"); 
      ptr=strchr(string,c); 
      if(ptr) 
          printf("Thecharacter%cisatposition:%d\n",c,ptr-string); 
      else 
          printf("Thecharacterwasnotfound\n"); 
      return0; 
 } 

函数名:strcmp 

 

功 能: 

 

串比较

 

用 法:intstrcmp(char*str1,char*str2); 
看 Asic 码,str1>str2,返回值>0;两串相等,返回 0 
程序例: 

#include<string.h> 
#include<stdio.h> 

intmain(void) 
 { 
      char*buf1="aaa",*buf2="bbb",*buf3="ccc"; 
      intptr; 

      ptr=strcmp(buf2,buf1); 
      if(ptr>0) 
          printf("buffer2isgreaterthanbuffer1\n"); 
      else 
          printf("buffer2islessthanbuffer1\n"); 

      ptr=strcmp(buf2,buf3); 
      if(ptr>0)