{ char *string1 = "1234567890";char *string2 = "747DC8";int length;length = strcspn(string1, string2);printf("Character where strings intersect is at position %dn", length);return 0;}
函数名: 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("%sn", dup_str);free(dup_str);return 0;}
函数名: 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 1n");if (ptr < 0)
printf("buffer 2 is less than buffer 1n");if (ptr == 0)
printf("buffer 2 equals buffer 1n");return 0;}
函数名: strerror功 能: 返回指向错误信息字符串的指针用 法: char *strerror(int errnum);程序例:#include <stdio.h> #include <errno.h> int main(void)
{ char *buffer;buffer = strerror(errno);printf("Error: %sn", buffer);return 0;}
函数名: 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 1n");if (ptr < 0)
printf("buffer 2 is less than buffer 1n");if (ptr == 0)
printf("buffer 2 equals buffer 1n");return 0;}
函数名: strncmp功 能: 串比较用 法: int strncmp(char *str1, char *str2, int maxlen);程序例:#include <string.h> #include <stdio.h> int main(void)
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-33642-8.html
送他们去见上帝
有没有给美帝抓住的内容