标题:帮我看下main函数怎样写啊(建立链表输入数据)
只看楼主
liuli01282379
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-4-5
 问题点数:0 回复次数:0 
帮我看下main函数怎样写啊(建立链表输入数据)
#include<stdio.h>
#include<malloc.h>

struct student
{
int num;
  char name[12];
  int score;
  struct student *next;
};
struct student *creat(void)
{
 int i, n; struct student *head, *p, *r;
  head=(struct student *)malloc(sizeof(struct student));
  head->next=NULL;
  r=head;
  printf("请输入学生人数:\n");
  scanf("%d",&n);
  for(i=1; i<=n; i++)
  { p=(struct student *)malloc(sizeof(struct student));
    printf("输入学生的学号:\n");
    scanf("%d", &p->num);
    printf("输入学生的姓名:\n");
    scanf("%s", p->name);
    printf("输人学生的成绩:\n");
    scanf("%d", &p->score);
    p->next=NULL;
    r->next=p;
    r=r->next; }
  return(head);
}
void main()
{
  struct student *p;

  p=create();
}
搜索更多相关主题的帖子: 链表 main 函数 数据 输入 
2008-04-09 17:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-208038-1-1.html




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

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