常用字符串函数.doc

常用字符串函数.doc

ID:56716347

大小:26.50 KB

页数:3页

时间:2020-07-05

常用字符串函数.doc_第1页
常用字符串函数.doc_第2页
常用字符串函数.doc_第3页
资源描述:

《常用字符串函数.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、1.函数名:stpcpy功能:拷贝一个字符串到另一个用法:char*stpcpy(char*destin,char*source);后面的复制给前面的2.函数名:strcpy功能:串拷贝用法:char*strcpy(char*str1,char*str2);3.函数名:strcat功能:字符串拼接函数用法:char*strcat(char*destin,char*source);例:chars[10];strcpy(s,”abc”);strcat(s,”abc”);printf(“%s”,s);输出abcdef。4

2、.函数名:strchr功能:在一个串中查找给定字符的第一个匹配之处用法: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:%d",c,ptr);elsepr

3、intf("Thecharacterwasnotfound");return0;}输出Thecharacter%cisatposition:125.函数名:strcmp功能:串比较用法:intstrcmp(char*str1,char*str2);看Asic码,str1>str2,返回值>0;两串相等,返回0;str1

4、用法:intstrncmp(char*str1,char*str2,intmaxlen);2.函数名:strncmpi功能:把串中的一部分与另一串中的一部分比较,不管大小写用法:intstrncmpi(char*str1,char*str2,intmaxlen);3.函数名:strpbrk功能:在串中查找给定字符集中的字符用法:char*strpbrk(char*str1,char*str2);char*string1="abcdefghijklmnopqrstuvwxyz";char*string2="onm";

5、char*ptr;ptr=strpbrk(string1,string2);ptr为m4.函数名:strrev功能:串倒转用法:char*strrev(char*str);例:strrev(“abc”);输出cba5.函数名:strset功能:将一个串中的所有字符都设为指定字符用法:char*strset(char*str,charc);6.函数名:strspn功能:在串中查找指定字符集的子集的第一次出现用法:intstrspn(char*str1,char*str2);7.函数名:strupr功能:将串中的小写字

6、母转换为大写字母用法:char*strupr(char*str);8.函数名:strtol功能:将串转换为长整数用法:longstrtol(char*str,char**endptr,intbase);例:char*string="87654321",*endptr;longlnumber;lnumber=strtol(string,&endptr,10);输出lnumber为87654321长整型数。1.函数名:strtod功能:将字符串转换为double型值用法:doublestrtod(char*str,ch

7、ar**endptr);例:charinput[80],*endptr;doublevalue;gets(input);value=strtod(input,&endptr);输入654321,输出value值为654321.000000为double型2.函数名:swab功能:交换字节用法:voidswab(char*from,char*to,intnbytes);例:charsource[15]="rFnakoBlrnad";chartarget[15];swab(source,target,strlen(so

8、urce));target变为FrankBorland

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

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

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