关于fread函数的问题
请问为什么在这个程序中不能将test1.a和test1.b的值分别赋给test2.c和test2.d???程序代码:
#include<stdio.h> struct x{ int a; int b; }; struct y{ int c; int d; }; int main(){ FILE *fp1,*fp2; struct x test1 = {1,2}; struct y test2 = {3,4}; fp1 = fopen("test.dat","w+b"); fp2 = fopen("test.dat","r+b"); fwrite(&test1.a,sizeof(test1.a),1,fp1); fwrite(&test1.b,sizeof(test1.b),1,fp1); fread(&test2.c,sizeof(test1.a),1,fp2); fread(&test2.d,sizeof(test1.b),1,fp2); fclose(fp1); fclose(fp2); printf("%d,%d\n",test2.c,test2.d); return 0; }