结构体定义后面不能直接定义指针*p。
如果需要定义一个结构体的指针,必须要使用malloc分配内存空间。否则就会出错。
#include
#include
typedef struct student
{
char name[20];
char num[20];
} student;
int main()
{
student a;
struct student *p = ( struct student *) malloc(sizeof(student));
gets(a.name);
puts(a.name);
fflush(stdin);
gets(p->name);
puts(p->name);
return 0;
}