C语言中bcmp是哪个库的函数?(在线等...)
bcmp不是string库的函数吗?但是我写的一个测试程序在VC6运行,怎么说我没有定义呢:
#include <string.h>
#include <stdio.h>
int main()
{
char *str1= "I 'm sky2098,welcome to my website! ";
char *str2= "I 'm sky2098,please do not call me sky2098! ";
int inttemp;
inttemp=bcmp(str1,str2,strlen( "I 'm sky2098, "));
if(inttemp==0)
{
printf( "str1 and str2 has n bytes which are the same as each other! ");
}
return 0;
}
错误提示信息:
D:\Program Files\Microsoft Visual Studio\MyProjects\strrev\bcmp.cpp(9) : error C2065: 'bcmp ' : undeclared identifier
这是什么原因呢?是VC6没有添加string这个库中的bcmp函数吗?
[解决办法]
没有bcmp
有strcmp,strncmp,memcmp
[解决办法]
属于linux下面的
在vc下面,使用memcmp即可
[解决办法]
ls正解
[解决办法]
属于linux下面的
你可以用memcmp
[解决办法]
弄个手册看看比较好。
[解决办法]
好像它是从BSD过来了, 不过这个函数过时了deprecated. 建议用memcmp
bcmp - compare byte sequences
SYNOPSIS
#include <strings.h>
int bcmp(const void *s1, const void *s2, size_t n);
DESCRIPTION
The bcmp() function compares the two byte sequences s1 and s2 of length n each. If they are equal, and in particular if n
is zero, bcmp() returns 0. Otherwise it returns a non-zero result.
RETURN VALUE
The bcmp() function returns 0 if the byte sequences are equal, otherwise a non-zero result is returned.
CONFORMING TO
4.3BSD. This function is deprecated -- use memcmp in new programs.
[解决办法]
函数名称: memcmp
函数原型: int memcmp(const void *s1, const void *s2,size_t n)
函数功能: 按字典顺序比较两个串s1和s2的前n个字节
函数返回: <0,=0,> 0分别表示s1 <,=,> s2
参数说明: s1,s2-要比较的字符串,n-比较的长度
所属文件: <string.h> , <mem.h>
#include <stdio.h>
#include <string.h>
int main()
{
char *buf1= "ABCDE123 ";
char *buf2= "abcde456 ";
int stat;
stat=memcmp(buf1,buf2,5);
printf( "The strings to position 5 are ");
if(stat) printf( "not ");
printf( "the same\n ");
return 0;
}