C语言 给我写个 链表

来源:百度知道 编辑:UC知道 时间:2024/06/29 03:00:56
#include<stdio.h>
#include<malloc.h>
#define N 2
#define NULL 0
#define LEN sizeof(STUDEN)
typedef struct student
{
int num;
char name[20];
char py[20];
float sc[2];
float average;
float sum;
struct student *next;
}STUDEN;
int m;
STUDEN *input(void)//输入
{
int i;float s;
STUDEN *head;
STUDEN *p1;
head=NULL;
printf("输入0结束输入\n");
while(1)
{
m=m+1;s=0;
printf("请输入第%d个:\n",m);
p1=(STUDEN *)malloc(LEN);
printf("学号:");
scanf("%d",&p1->num);
if(p1->num==0)break;
printf("姓名:");
scanf("%s",&p1->name);
printf("专业:");
scanf("%s",&p1->py);
printf("输入成绩\n:");
for(i=0;i<N;i++)
{
if(i==0)printf("语文:");
if(i==1)pr

#include<stdio.h>
#include<malloc.h>

#define N 2
#define NULL 0
#define LEN sizeof(STUDEN)

typedef struct student
{
int num;
char name[20];
char py[20];
float sc[N];////2修改为N
float average;
float sum;
struct student *next;
}STUDEN;

int m=0;/////////初始化为0
//我看到m在下面程序中除了自加自减外,无其他用途,建议去掉

STUDEN *input(void)//输入
{
int i;float s;
STUDEN *head;
STUDEN *p1;

head=NULL;
printf("输入0结束输入\n");
while(1)
{
m=m+1;s=0;
printf("请输入第%d个:\n",m);
p1=(STUDEN *)malloc(LEN);
if(p1==0)
{
/////建议添加错误处理的代码,以防出现内存申请不到的情况
}
printf("学号:");
scanf("%d",&p1->num);
if(p1->num==0)
break;
printf("姓名:");
scanf("%s",&p1->name);
printf("专业:");
scanf(&