#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct scorenode)
#define DEBUG
#include <string.h>
struct scorenode
{int number;/*学号*/
char name[10];/*姓名*/
float xiaofei;/*消费情况*/
struct scorenode *next;
};
typedef struct scorenode score;
int n,k;/*n,k为全局变量,本程序中的函数均可以使用它*/
/*==============================================================================================*/
score *creat2311(void)
/*函数creat2311,功能:创建链表,此函数带回一个指向链表头的指针*/
{
score*head;
score *p1,*p2,*p3,*max;
int i,j;
float fen;
char t[10];
n=0;
p1=p2=p3=(score *)malloc(LEN);head=p3; /*开辟一个新单元*/
printf("please input the student's information.when you input 0,exit\n");
repeat1: printf("please input student's number(number>0):");/*输入学号,学号应大于0*/
scanf("%d",&p1->number);
while(p1->number<0)
{getchar();
printf("error due to the wrong input,please input it again:");
scanf("%d",&p1->number);}
/*输入学号为字符或小于0时,程序报错,提示重新输入学号*/
if(p1->number==0)
goto end;/*当输入的学号为0时,转到末尾,结束创建链表*/
else
{
p3=head;
if(n>0)
{for(i=0;i<n;i++)
{if(p1->number!=p3->number)
p3=p3->next;
else
{printf("a same number exsit!please input it again!\n");
goto repeat1;
/*当输入的学号已经存在,程序报错,返回前面重新输入*/
}
}
}
}
printf("please input student's name:");
scanf("%s",&p1->name);/*输入学生姓名*/
printf("please input the expenture:");/*输入消费情况;
head=NULL;
while(p1->number!=0)
{
n=n+1;
if(n==1)
head=p1;