memcmp的问题

来源:互联网 发布:饥荒mac版mod 编辑:程序博客网 时间:2024/05/21 06:02
#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;} 

原创粉丝点击