}
5、函数名: strncmp
功 能: 将一个串中的一部分与另一个串比较, 大小写敏感
用 法: int strncmp(char *str1, char *str2, size_t maxlen);
程序例:
#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/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
5.1、函数名: strncmpi(还有一种写法是strnicmp,VC 6.0都支持)
功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写
用 法: 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 1/n");
if (ptr < 0)
printf("buffer 2 is less than buffer 1/n");
if (ptr == 0)
printf("buffer 2 equals buffer 1/n");
return 0;
}
其它参考:
int memcmp ( const void * ptr1, const void * ptr2, size_t num );
int strcoll ( const char * str1, const char * str2 );
size_t strxfrm ( char * destination, const char * source, size_t num );
Part 4: Searching
6、函数名: strchr
用 法: char *strchr(char *str, char c);
功 能: 在一个串中查找给定字符的第一个匹配之处(Locate first occurrence of character in string, Returns a pointer to the first occurrence of character in the C string str. The terminating null-character is considered part of the C string. Therefore, it can also be located to retrieve a pointer to the end of a string.)
程序例:
#include <string.h>
#include <stdio.h>
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-33666-3.html
统一是大势所趋
这样大家都各取所需
我不追星
不要中小人奸计