c语言改错题,求大神指点!!! 5

下列给定程序中,函数Creat的功能是:创建一个学生链表,并返回链表头指针,Put函数输出链表结点。#include<stdio.h>#include<stdlib.h>... 下列给定程序中, 函数Creat的功能是:创建一个学生链表,并返回链表头指针,Put函数输出链表结点。
#include <stdio.h>
#include <stdlib.h>
#define LENGTH sizeof(struct stulink)
struct stulink
{
long num; //学号
char name[20]; //姓名
int score; //成绩
struct stulink *next; //指向结构体的指针变量
};

int main()
{
struct stulink *Creat(struct stulink *);
void Put(struct stulink *);
struct stulink *head=NULL;
head=Creat(head);
Put(head);
return 0;
}
struct stulink *Creat(struct stulink *head)
{

int i,n;
struct stulink *p,*pr;

printf("input the number of student's ");
scanf("%d",&n);

for(i=1;i<=n;i++)
{
p=(struct stulink *)malloc(LENGTH);
if(p==NULL)
{
printf("No enough memory to allocate!\n");
exit(0);
}
if(head==NULL)
head=p;
else
pr->next=p;

printf("input the N0 %d student num name score:\n",i);
scanf("%ld%s%d",&p->num,&p->name,&p->score);
p->next=NULL;
pr=p;
}
return(head);
}

void Put(struct stulink *head)
{
struct stulink *p=head;

printf("num name score\n");
while(p!=NULL)
{
printf("%ld\t%-10s %-3d\n",p->num,p->name,p->score);
p=p->next;
}
}
展开
 我来答
xoaxa
2017-11-17 · TA获得超过8605个赞
知道大有可为答主
回答量:6415
采纳率:72%
帮助的人:3374万
展开全部

#include <stdio.h>
#include <stdlib.h>

#define LENGTH sizeof(struct stulink)
struct stulink {
long num; //学号
char name[20]; //姓名
int score; //成绩
struct stulink *next; //指向结构体的指针变量
};

struct stulink *Creat() {
int T,n;
struct stulink *p,*head;
p = head = (struct stulink *)malloc(LENGTH);
printf("input the number of student's :");
scanf("%d",&n);
T = n;
while(T--) {
p->next = (struct stulink *)malloc(LENGTH);
if(p->next == NULL) {
printf("No enough memory to allocate!\n");
exit(0);
}
printf("输入学号 姓名 成绩 : ");
scanf("%ld%s%d",&p->next->num,p->next->name,&p->next->score);
p = p->next; 
}
 p->next = NULL;
 return head;
}

void Put(struct stulink *head) {
struct stulink *p = head->next;
printf("num\tname\tscore\n");
while(p) {
printf("%ld\t%-10s %-3d\n",p->num,p->name,p->score);
p = p->next;
}
}

int main() {
struct stulink *head = Creat();
Put(head);
return 0;
}
Eddy8
2017-11-17 · TA获得超过533个赞
知道小有建树答主
回答量:315
采纳率:90%
帮助的人:162万
展开全部
这题没错啊,这代码没错啊,我测试了,运行没有问题
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式