2012-02-11 19:49:27|?次阅读|上传:wustguangh【已有?条评论】发表评论
关键词:C/C++, 字符处理|来源:唯设编程网
8.函数名: strdup
功 能: 将串拷贝到新建的位置处
用 法: char *strdup(char *str);
程序例:
#include <stdio.h>
#include <string.h>
#include <alloc.h>
int main(void)
{
char *dup_str, *string = "abcde";
dup_str = strdup(string);
printf("%s
", dup_str);
free(dup_str);
return 0;
}
9.函数名: stricmp
功 能: 以大小写不敏感方式比较两个串
用 法: int stricmp(char *str1, char *str2);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = stricmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1
");
if (ptr < 0)
printf("buffer 2 is less than buffer 1
");
if (ptr == 0)
printf("buffer 2 equals buffer 1
");
return 0;
}
10.函数名: strerror
功 能: 返回指向错误信息字符串的指针
用 法: char *strerror(int errnum);
程序例:
#include <stdio.h>
#include <errno.h>
int main(void)
{
char *buffer;
buffer = strerror(errno);
printf("Error: %s
", buffer);
return 0;
}
11.函数名: strcmpi
功 能: 将一个串与另一个比较, 不管大小写
用 法: int strcmpi(char *str1, char *str2);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf2 = "bbb";
int ptr;
ptr = strcmpi(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1
");
if (ptr < 0)
printf("buffer 2 is less than buffer 1
");
if (ptr == 0)
printf("buffer 2 equals buffer 1
");
return 0;
}