首页 > 编程知识 正文

Linux stricmp函数 库函数 strpbrk strcasecmp strspn,acm能调用库函数

时间:2023-05-06 17:54:50 阅读:221153 作者:1920

strpbrk函数

函数原型:extern char *strpbrk(char *str1, char *str2)

参数说明:str1待比较的字符串,str2为指定被搜索的字符串。

所在库名:#include

函数功能:比较字符串str1和str2中是否有相同的字符,如果有,则返回该字符在str1中的位置的指针。

返回说明:返回指针,搜索到的字符在str1中的索引位置的指针。

例子:

#include

#include

#include

int main(int argc, char *argv[])

{

char *a = "aBcDeF";

char *b = "AbCdEf";

char* c = strpbrk(a, "c");

printf("%sn", c);

return 0;

}

执行 cDeF

strcasecmp(忽略大小写比较字符串)

函数原型: int strcasecmp (const char *s1, const char *s2);

所在库名:#include (不是C/C++的标准头文件,区别于string.h[1] )

函数功能:用来比较参数s1和s2字符串,比较时会自动忽略大小写的差异。

返回说明:若参数s1和s2字符串相等则返回0。s1大于s2则返回大于0 的值,s1 小于s2 则返回小于0的值。

例子:

#include

main()

{

char *a="aBcDeF";

char *b="AbCdEf";

if(!strcasecmp(a,b))

printf("%s=%sn",a,b);

}

执行 aBcDeF=AbCdEf

注释:该函数是二进制安全的,且对大小写不敏感。此函数只在Linux中提供,相当于windows平台的 stricmp。

strspn(返回字符串中第一个不在指定字符串中出现的字符下标)

函数原型:size_t strspn (const char *s,const char * accept);

所在库名:#include

函数功能:从参数s 字符串的开头计算连续的字符,而这些字符都完全是accept 所指字

0符串中的字符。简单的说,若strspn()返回的数值为n,则代表字符串s 开头连续有n 个字符都是属于字符串accept内的字符。

返回说明:返回字符串s开头连续包含字符串accept内的字符数目。

例子:

#include

main()

{

char* str = "Linux was first developed for 386/486-based pcs";

printf("%dn", strspn(str, "Linux"));

printf("%dn", strspn(str, "/-"));

printf("%dn", strspn(str, "1234567890"));

}

执行:

5

0

原文:http://www.cnblogs.com/AngelAI/p/3873714.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。