7-1 学生信息输入输出

7-1 学生信息输入输出

输入若干个学生的信息(学号、姓名、成绩),当输入学号为0时结束,用单向链表组织这些学生信息后,再按顺序输出。写自定义目录标题)

输入样例
1 zhang 78
2 wang 80
3 li 75
4 zhao 85
0
输出样例
1 zhang 78
2 wang 80
3 li 75
4 zhao 85

#include 
#include 

struct node
{
     
    char name[10];
    int num,score;
    struct node *next;
};
struct node *create()
{
     

    struct node *Head,*p,*tail;
    int date;
    Head = (struct node *)malloc(sizeof(struct node));
    Head->next = NULL;
    tail = Head;
    p = (struct node *)malloc(sizeof(struct node));
    p->next = NULL;
    while(scanf("%d",&date) != EOF)

                       
    {
     
        if(date == 0) break;
        p->num = date;
        scanf("%s %d",p->name,&p->score);
        tail->next = p;
        tail = p;
        p = (struct node *)malloc(sizeof(struct node));
        p->next = NULL;
    }
    return Head;
}
void print(struct node *Head)
{
     
    struct node *p;
    p = Head->next;
    while(p != NULL)
    {
     
        printf("%d %s %d\n",p->num,p->name,p->score);
        p = p->next;
    }
}
int main()
{
     
    struct node *head;
    head = create();
    print(head);
    return 0;
}

你可能感兴趣的:(7-1 学生信息输入输出)