其他函数无法调用一个函数中以输入的链表
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#include "displayMenu.h"
typedef struct stu{
int stu_id;
char name[10];
int score;
struct stu *next;
}stu;
stu * stulist=NULL;
stu * inputInfo(stu * stulist);
void outputInfo(stu * stulist);
void queryInfo(stu * stulist);
stu * sortScore(stu * stulist );
stu * addInfo(stu * stulist);
void displayMenu(){
char choose;
while(1){
printf("Welcome to the Student achievement management system\n");
printf("1.Input student's information\n");
printf("2.Output student's information\n");
printf("3.Search the student's score\n");
printf("4.Sort the student's score\n");
printf("5.Add new student information\n");
printf("6.Quit the system\n");
printf("Please choose the part of the system your want to go by input the number before every part\n");
scanf("\n%c" ,&choose);
if(choose=='1'){ printf("We will go to the input system soon\n");
inputInfo(stulist );
}
else if (choose=='2'){ printf("We will go to the output system soon\n");
outputInfo(stulist);
}
else if (choose=='3'){ printf("We will go to the search system soon\n");
queryInfo(stulist);
}
else if (choose=='4'){ printf("We will go to the sort system soon\n");
sortScore(stulist);
}
else if (choose=='5'){ printf("We will add some new information\n");
addInfo(stulist);
}
else if (choose=='6'){
printf("The system will exit .Thanks for using\n");
exit(0);
}
getch();
}
}
stu * inputInfo(stu * stulist ){
int i , stu_num;
stu * pO =NULL, * pN =NULL ;
printf("The number of the students that your want to input\n");
scanf("%d" , &stu_num);
while(stu_num>20||stu_num<=0){ /*控制输入信息的学生个数*/
printf("The system can at most hold 20 student, please reinput\n");
stu_num=GetInteger();
}
for(i=1; i<=stu_num ; i++){
pN = (stu * )malloc(sizeof(struct stu));
if (stulist==NULL) {/*判断是否是第一次输入*/
stulist=pN; /*定义头指针*/
}
else {
pO->next=pN; /*使其链接到下一个结构体*/
}
pN->next=NULL; /*每一个结构体都可能是最后一个,所以将现在的结构体中指向下一个结构体的指针定为空指针*/
printf("Please input the student's id\n");
scanf("%d" , &pN->stu_id);
while(uniqueNumber(stulist,pN->stu_id)==1){
printf("The ID you put in is already there,please reinput\n");
strcpy(pN->stu_id,GetInteger());
}
printf("Please input the student's name\n");
scanf("%s" ,& pN->name);
printf("Please input the student's score\n");
scanf("%d" , &pN->score);
while(checkscore(pN->score)==1){
printf("The Score you put in is out of range,please keep it from 0 to 100\n");
scanf("%d" , &pN->score);
}
pO=pN;
return(stulist);
}
}
void outputInfo(stu * stulist){
stu * pN;
pN=stulist;
if(pN!=NULL){
while (pN->next!=NULL){
printf("ID :%d , Name: %s , Score : %d .\n" , pN->stu_id , pN->name , pN->score);
pN=pN->next;
}
}
else if(pN==NULL) {
printf("The system don't have any information. Please input some first\n");
}
}
这样,一旦在input中输入了信息,但是在选择output后却显示了 pN==NULL那种情况下的语句