帮忙看一下 *p->x = a; 为什么不行 该怎么该?
宙斯之神 2006-10-02 03:16:43 #include "malloc.h"
#include "stdio.h"
struct data{
int x;
int y;
};
int getCoordX(struct data *p)
{
return p->x;
}
int getCoordY(struct data *p)
{
return p->y;
}
void CoordCons(struct data **p,int a, int b)
{
*p= (struct data*)malloc(sizeof(struct data));
*p->x = a;
*p->y = b;
}
void main()
{
struct data *a=NULL;
CoordCons(&a,3,4);
int x;
x = getCoordX(a);
int y;
y = getCoordY(a);
printf("%d %d ",x,y);
}