c 字符串操作函数

c 字符串操作函数

ID:18294781

大小:72.00 KB

页数:22页

时间:2018-09-16

c 字符串操作函数_第1页
c 字符串操作函数_第2页
c 字符串操作函数_第3页
c 字符串操作函数_第4页
c 字符串操作函数_第5页
资源描述:

《c 字符串操作函数》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、C字符串操作函数函数名:stpcpy功能:拷贝一个字符串到另一个用法:char*stpcpy(char*destin,char*source);程序例:#include#includeintmain(void){charstring[10];char*str1="abcdefghi";stpcpy(string,str1);printf("%s",string);return0;}函数名:strcat功能:字符串拼接函数用法:char*strcat(char*destin,char*source

2、);程序例:#include#includeintmain(void){chardestination[25];char*blank="",*c="C++",*Borland="Borland";strcpy(destination,Borland);strcat(destination,blank);strcat(destination,c);printf("%s",destination);return0;}函数名:strchr功能:在一个串中查找给定字符的第一个匹配之处用法:char*s

3、trchr(char*str,charc);程序例:#include#includeintmain(void){charstring[15];char*ptr,c='r';strcpy(string,"Thisisastring");ptr=strchr(string,c);if(ptr)printf("Thecharacter%cisatposition:%d",c,ptr-string);elseprintf("Thecharacterwasnotfound");return0;}函数名

4、: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("buffer2isgreaterthanbuffer1");elseprintf("buffer2isl

5、essthanbuffer1");ptr=strcmp(buf2,buf3);if(ptr>0)printf("buffer2isgreaterthanbuffer3");elseprintf("buffer2islessthanbuffer3");return0;}函数名:strncmpi功能:将一个串中的一部分与另一个串比较,不管大小写用法:intstrncmpi(char*str1,char*str2,unsignedmaxlen);程序例:#include#includeintm

6、ain(void){char*buf1="BBB",*buf2="bbb";intptr;ptr=strcmpi(buf2,buf1);if(ptr>0)printf("buffer2isgreaterthanbuffer1");if(ptr<0)printf("buffer2islessthanbuffer1");if(ptr==0)printf("buffer2equalsbuffer1");return0;}函数名:strcpy功能:串拷贝用法:char*strcpy(char*str1,char*str2);程序例:

7、#include#includeintmain(void){charstring[10];char*str1="abcdefghi";strcpy(string,str1);printf("%s",string);return0;}函数名:strcspn功能:在串中查找第一个给定字符集内容的段用法:intstrcspn(char*str1,char*str2);程序例:#include#include#includeintmain(void

8、){char*string1="1234567890";char*string2="747DC8";intlength;length=strcspn(string1,string2);printf("Cha

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。