| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 540 人关注过本帖
标题:求助,要求建立一个链表输出每个学生的学号,姓名,性别,年龄等信息
只看楼主 加入收藏
中华神盾
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-9-1
结帖率:100%
收藏
 问题点数:0 回复次数:0 
求助,要求建立一个链表输出每个学生的学号,姓名,性别,年龄等信息
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct student)
#define N 4
struct student
{
    int num;
    char name[8];
    char sex[2];
    int age;
    struct student *next;
};
void main()
{
    int i;
    struct student *head,*p,*q;
   
    printf("请输入学生信息\n:");
    head=(struct student*)malloc(LEN);

for(i=0;i<N;i++)
{
    if(i==0)
        p=q=head;
    else
        q->next=p;
    q=p;

        p=(struct student*)malloc(LEN);
    printf("学号:");
    scanf("%d",&p->num);
    printf("\n姓名:");
    scanf("%s",&p->name);
    printf("\n性别:");
    scanf("%c",&p->sex);
    printf("\n年龄:");
    scanf("%d",&p->age);
   
    }
    printf("学号  姓名  性别  年龄\n");
    p=head;
    while(p!=NULL)
    {
        printf("%d%s%c%d\n",p->num,p->name,p->sex,p->age);
        p=p->next;
    }
}
搜索更多相关主题的帖子: 信息 include next 
2012-09-03 16:55
快速回复:求助,要求建立一个链表输出每个学生的学号,姓名,性别,年龄等信息
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013634 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved