#include<string.h>
#include<stdio.h>
struct A{
int a;
char str[8];
int b;
};
struct B{
int a;
char str[8];
short b;
short c;
};
int main()
{
//返回0,但是不一样。
A a1;
B b1;
memset(&a1,0,sizeof(a1));
a1.a=1;
memcpy(a1.str,"hello",strlen("hello"));
a1.b=0x3f3f3f3f;
memset(&b1,0,sizeof(b1));
b1.a=1;
memcpy(b1.str,"hello",strlen("hello"));
b1.b=0x3f3f;
b1.c=0x3f3f;
printf("%d\n",memcmp(&a1,&b1,sizeof(a1)));
//不返回0,但是一样
char str1[10]="hello";
char str2[10]="hello";
str2[6]='5';
printf("%d\n",memcmp(str1,str2,10));
printf("%d\n",strcmp(str1,str2));
return 0;
}
memcmp的问题
最新推荐文章于 2022-07-21 02:58:13 发布