//
//思考:如何实现学生信息录入的动态长度控制?
//提示:使用链表,动态分配空间
//Student * p1;
//p1=malloc(sizeof(Student));
//p1->age=10;
//struct Node{
// Student stu;
// Node * next;
//}
#include <stdio.h>
#include <stdlib.h>
#define NUM 3
struct Student
{
char name[10];
int number;
int age;
int score;
struct Student *next;
};
int main(int argc, const char * argv[])
{
struct Student *head,*p,*q,stu;
//提示用户录入学生信息
head = NULL;
head=&stu;
p=head;
//p = head;
//head=p;
for (int i = 0; i < NUM; i ++) {
q = (struct Student*)malloc(sizeof(struct Student));
q->next=NULL;
if (head!=NULL)
{
p->next=q;
p=p->next;
}else if (head==NULL)
{
head=q;
p=q;
}
printf("请输入第%d名学生的信息:姓名 学号 年龄 成绩",i+1);
scanf("%s %d %d %d\n",p->name,&p->number,&p->age,&p->score);
}
p = head;
for (int i = 0; i < NUM; i ++) {
printf("第%d名学生的信息:姓名 学号 年龄 成绩",i+1);
printf("%s %d %d %d\n",p->name,p->number,p->age,p->score);
p=p->next;
}
printf("Hello, World!\n");
return 0;
}