problem with memcmp

#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;
};
intmain()
{
	//return 0, but not the same.
	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)));
	// does not return 0, but the same
	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;
}
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325894937&siteId=291194637