资源描述:
《c语言全总字符串函数》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、C语言全总字符串函数函数名:stpcpy功能:拷贝一个字符串到另一个用法:char*stpcpy(char*destin,char*source);程序例:#include#includeintmain(void){charstring[10];char*str1="abcdefghi";stpcpy(string,str1);printf("%sn",string);return0;}函数名:strcat功能:字符串拼接函数用法:char*strcat(char*destin,char*s
2、ource);程序例:#include#includeintmain(void){chardestination[25];char*blank="",*c="C++",*Borland="Borland";strcpy(destination,Borland);strcat(destination,blank);strcat(destination,c);printf("%sn",destination);return0;}函数名:strchr功能:在一个串中查找给定字符的第一个匹配之处用法
3、:char*strchr(char*str,charc);程序例:#include#includeintmain(void){charstring[15];char*ptr,c='r';strcpy(string,"Thisisastring");ptr=strchr(string,c);if(ptr)printf("Thecharacter%cisatposition:%dn",c,ptr-string);elseprintf("Thecharacterwasnotfoundn");ret
4、urn0;}函数名:strcmp功能:串比较用法:intstrcmp(char*str1,char*str2);看Asic码,str1>str2,返回值>0;两串相等,返回0程序例:#include#includeintmain(void){char*buf1="aaa",*buf2="bbb",*buf3="ccc";intptr;ptr=strcmp(buf2,buf1);if(ptr>0)printf("buffer2isgreaterthanbuffer1n");elseprintf
5、("buffer2islessthanbuffer1n");ptr=strcmp(buf2,buf3);if(ptr>0)printf("buffer2isgreaterthanbuffer3n");elseprintf("buffer2islessthanbuffer3n");return0;}函数名:strncmpi功能:将一个串中的一部分与另一个串比较,不管大小写用法:intstrncmpi(char*str1,char*str2,unsignedmaxlen);程序例:#include#include
6、intmain(void){char*buf1="BBB",*buf2="bbb";intptr;ptr=strcmpi(buf2,buf1);if(ptr>0)printf("buffer2isgreaterthanbuffer1n");if(ptr<0)printf("buffer2islessthanbuffer1n");if(ptr==0)printf("buffer2equalsbuffer1n");return0;}函数名:strcpy功能:串拷贝用法:char*strcpy(char*str1,c
7、har*str2);程序例:#include#includeintmain(void){charstring[10];char*str1="abcdefghi";strcpy(string,str1);printf("%sn",string);return0;}函数名:strcspn功能:在串中查找第一个给定字符集内容的段用法:intstrcspn(char*str1,char*str2);程序例:#include#include#include8、oc.h>intmain(void){char*string1="1234567890";char*string2="747DC8";intlength;length=strcspn(string1,string2);printf("Characterwhere