| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 385 人关注过本帖
标题:其他函数无法调用一个函数中以输入的链表
只看楼主 加入收藏
fyt10060
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-12-21
结帖率:0
收藏
 问题点数:0 回复次数:1 
其他函数无法调用一个函数中以输入的链表
#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那种情况下的语句
搜索更多相关主题的帖子: void 其他 management Welcome include 
2012-12-21 21:49
fyt10060
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-12-21
收藏
得分:0 
求专业人士,急需知道原因啊
2012-12-21 22:10
快速回复:其他函数无法调用一个函数中以输入的链表
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040829 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved