ptr = strcmp(buf2, buf1);
if (ptr0)
printf("buffer 2 is greater than buffer 1/n");
else if(ptr0)
printf("buffer 2 is less than buffer 1/n");
else
printf("buffer 2 is equal with buffer 1/n");
return 0;
}
/*运行结果:
buffer 2 is greater than buffer 1
*/
函数名: strncmpi
功能: 将一个串中的一部分与另一个串比较, 不管大小写
用法: int strncmpi(char *str1, char *str2, unsigned maxlen);
举例:
[cpp] view plain copy
#include string.h
#include stdio.h
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = strcmpi(buf2, buf1);
if (ptr0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
函数名: strcspn
功能: 在串中查找第一个给定字符集内容的段
用法: int strcspn(char *str1, char *str2);
举例:
[cpp] view plain copy
#include stdio.h
#include string.h
#include alloc.h
int main(void)
{
char *string1 = "1234567890";
char *string2 = "747DC8";
int length;
length = strcspn(string1, string2);
printf("Character where strings intersect is at position %d/n", length);
return 0;
}
函数名: strdup
功能: 将串拷贝到新建的位置处
用法: char *strdup(char *str);
举例:
[cpp] view plain copy
#include stdio.h
#include string.h
#include alloc.h
int main(void)
{
char *dup_str, *string = "abcde";
dup_str = strdup(string);
printf("%s/n", dup_str);
free(dup_str);
return 0;
}
函数名: stricmp
功能: 以大小写不敏感方式比较两个串
用法: int stricmp(char *str1, char *str2);
举例:
[cpp] view plain copy
#include string.h
#include stdio.h
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = stricmp(buf2, buf1);
if (ptr0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
函数名: strerror
功能: 返回指向错误信息字符串的指针
用法: char *strerror(int errnum);
举例:
[cpp] view plain copy
#include stdio.h
#include errno.h
int main(void)
{
char *buffer;
buffer = strerror(errno);
printf("Error: %s/n", buffer);
return 0;
}
函数名: strncmp
功能: 串比较
用法: int strncmp(char *str1, char *str2, int maxlen);
举例:
[cpp] view plain copy
#include string.h
#include stdio.h
intmain(void)
{
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
int ptr;
ptr = strncmp(buf2,buf1,3);
if (ptr0)
printf("buffer 2 is greater than buffer 1/n");
else
printf("buffer 2 is less than buffer 1/n");
ptr = strncmp(buf2,buf3,3);
if (ptr0)
printf("buffer 2 is greater than buffer 3/n");
else
printf("buffer 2 is less than buffer 3/n");
return(0);
}
函数名: strncmpi
功能: 把串中的一部分与另一串中的一部分比较, 不管大小写
用法: int strncmpi(char *str1, char *str2, int len);
举例:
[cpp] view plain copy
#include string.h
#include stdio.h
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strncmpi(buf2,buf1,3);
if (ptr0)
printf("buffer 2 is greater than buffer 1/n");
if (ptr0)
printf("buffer 2 is less than buffer 1/n");
推荐阅读
- 中健网公众号注册入口,中健公司
- ios双相机拍照软件,ios双相机拍照软件是什么
- 怎么快速迁移mysql数据库,mysql迁移数据库到另一台机器
- 登山赛车2相关游戏有哪些,登山赛车2小游戏
- des加密java代码 java实现des加密解密
- 软件公司软件代理合同范本,软件代理销售合同
- 怎样用js实现下拉框,js做下拉框
- go语言的包管理 go语言的包管理工具
- thinkphp隐藏号码,thinkphp隐藏入口文件