先看个小例子:
#include <stdio.h>
#include <stdlib.h>
struct test {
int a;
char b;
};
void main (void)
{
struct test *t;
t=(struct test *)malloc(sizeof(struct test));
*t={1, 'a'};
}
这有一个典型的错误,结构体的初始化和赋值的问题。
正确应该是:
(*t).a = 1;
(*t).b = 'a';