2007-10-18 12:07
wind0520
新手上路,各位大大救我一救!
在unix下,编译通过了,但执行时报 Memory fault(coredump) 错,各位仁兄帮我看一下:
#include <stdio.h>
main()
{
int x,y,z=1234;
int *point,*point1,*point2;
int size;
FILE *fp;
struct Fstruct {
int FirstVar;
char SecondVar[10];
} Fstruct[1],Sstruct[1];
y=15;x=9;
point=&z;
point1 = &x;
point2 = &y;
Fstruct[0].FirstVar=101;
strcpy(Fstruct[0].SecondVar, "ABCDEFGHGH");
Fstruct[1].FirstVar=202;
strcpy(Fstruct[1].SecondVar, "HIJKLMNNMN");
fp = fopen("a.txt","w+b");
size=fwrite(Fstruct, sizeof(Fstruct), 2, fp);
fclose(fp);
printf("size=[%d]\n\n",size);
fp=fopen("a.txt","rb");
fread(Sstruct,sizeof(Sstruct), 2, fp);
printf("Sstruct[0].SecondVar=%s\n\n",Sstruct[0].SecondVar);
fclose(fp);
max(x,y,point,point1,point2);
printf("*point=[%d]\n",*point);
}
int max(int x,int y,int *point,int *point1,int *point2)
{
if(x<y)
*point = *point1;
else *point = *point2;
return 0;
}