柳河早市杀人案:指针结构体的问题,急求帮助

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/06 13:51:13
(1) char **p;
*p=(char *)malloc(sizeof(char));
谁能告诉我为什么错的
(2)typedef struct
{
int i;
char ch;
}struct1;
typedef struct
{
int j;
struct1 *A;
}struct2;

main()
{
struct2 *node=(struct2 *)malloc(sizeof(struct2));
//node->A->ch='A';//error,为什么不行?
//如果把上面的struct1 *A;换成struct A;,然后用node->A.ch='A'赋值又可以了!
//为什么?
}

(1)char **p;
char *tp;
*p = tp;//指针也要有实体的.
*p=(char *)malloc(sizeof(char));

(2)struct2 *node=(struct2 *)malloc(sizeof(struct2));
struct1 tA;
node->A = &tA;
node->A->ch='A';//跟上面的问题是一样的