当前位置: 代码迷 >> C语言 >> 帮我看下main函数怎样写啊(建立链表输入数据)
  详细解决方案

帮我看下main函数怎样写啊(建立链表输入数据)

热度:129   发布时间:2008-04-09 17:59:48.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  函数  数据  输入  

----------------解决方案--------------------------------------------------------
  相关解决方案