动态结构体的问题
看代码程序代码:
/* 动态输入学生个数,并输入姓名,学号,和一门成绩! */ #include "stdio.h" #include "stdlib.h" struct STUDENT { int number; char name[15]; int score; }; void main() { printf("Hello World!\n"); struct STUDENT *p;//这要不要用*p=NULL; int n; printf("Please enter n:"); scanf("%d", &n); p=(struct STUDENT *)malloc(sizeof(struct STUDENT)*n); if(p==NULL) { printf("No enough memory!\n"); exit(0); } for(i=0; i < n; i++) { printf("Please enter the student's number:"); scanf("%d", p.number); printf("Please enter the student's name:"); scanf("%s", p.name); printf("Please enter the student's score:"); scanf("%d", p.score); } for(i=0; i < n; i++) { printf("姓名:%s\n学号:%d\n成绩:%d\n", p.name, p.number, p.score); } free(p); return 0; } //错误在哪里,如何改正?要注意什么? //想问下,如果输入多门成绩,要如何修改?