{ char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";int ptr;ptr = strncmp(buf2,buf1,3);if (ptr > 0)
printf("buffer 2 is greater than buffer 1n");else printf("buffer 2 is less than buffer 1n");ptr = strncmp(buf2,buf3,3);if (ptr > 0)
printf("buffer 2 is greater than buffer 3n");else printf("buffer 2 is less than buffer 3n");return(0);}
函数名: strncmpi功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写用 法: int strncmpi(char *str1, char *str2);程序例:#include <string.h> #include <stdio.h> int main(void)
{ char *buf1 = "BBBccc", *buf2 = "bbbccc";int ptr;ptr = strncmpi(buf2,buf1,3);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;}
函数名: strncpy功 能: 串拷贝用 法: char *strncpy(char *destin, char *source, int maxlen);程序例:#include <stdio.h> #include <string.h> int main(void)
{ char string[10];char *str1 = "abcdefghi";strncpy(string, str1, 3);string[3] = '';printf("%sn", string);return 0;}
函数名: strnicmp功 能: 不注重大小写地比较两个串用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);程序例:#include <string.h> #include <stdio.h> int main(void)
{ char *buf1 = "BBBccc", *buf2 = "bbbccc";int ptr;ptr = strnicmp(buf2, buf1, 3);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;}
函数名: strnset功 能: 将一个串中的所有字符都设为指定字符用 法: char *strnset(char *str, char ch, unsigned n);程序例:#include <stdio.h> #include <string.h> int main(void)
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-33642-9.html
敢于鼓足勇气对美国说关你鸟事
欢迎提出宝贵意见
我没觉得台湾香港人享受更高品质生活