| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 905 人关注过本帖
标题:小菜,求助学生分数管理系统的改错
只看楼主 加入收藏
早起的月光
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-11-6
收藏
 问题点数:0 回复次数:0 
小菜,求助学生分数管理系统的改错
我编了个学生分数管理系统但总是出现内存分配错误,请问下问题出在哪?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<malloc.h>
struct student{
    char name[20];
    int score;
    struct student *next;
};
struct student *ptr,*head,*this,*prev;
void ini_func(void);
void insert_func(void);
void sort_func(void);
void delete_func(void);
void modify_func(void);
void display_func(void);
void anykey_func(void);
int main()
{
    char option;
    ini_func();
    while(1){
        printf("*********************\n");
        printf("1               insert\n");
        printf("2               delete\n");
        printf("3              display\n");
        printf("4               modify\n");
        printf("5                 quit\n");
        printf("*********************\n");
        printf("please enter your choose");
        option=getche();
        printf("\n");
        switch(option){
            case '1':
                insert_func();
                break;
            case '2':
                delete_func();
                break;
            case '3':
                display_func();
                break;
            case '4':
                modify_func();
                break;
            case '5':
                exit(0);
            defult:
                printf("error!please enter again\n");
        }
    }
return 0;
}
void ini_func(void)
{
    head=(struct student*)malloc(sizeof(struct student));
    head->next=NULL;
}
void insert_func(void)
{
    char s_temp[4];
    ptr=(struct student*)malloc(sizeof(struct student));
    if(!ptr)exit(0);
    printf("plese enter the students name ");
    gets(ptr->name);
    printf("please enter the students store ");
    gets(s_temp);
    ptr->score=atoi(s_temp);
    
    sort_func();
}
void sort_func(void)
{
    prev=head;
    this=head->next;
    while(!this&&(ptr->score>this->score)){
        prev=this;
        this=this->next;
    }
    ptr->next=this;
    prev->next=ptr;
}
void delete_func(void)
{
    char de_name[20];
    printf("delete student name\n");
    gets(de_name);
    prev=head;
    this=head->next;
    while(!this&&strcmp(this->name,de_name)){
        prev=this;
        this=this->next;
    }
    if(this){
        prev->next=this->next;
        free(this);
    }else{
        printf("no the name\n");
    }
    anykey_func();
}
void modify_func(void)
{
    char mo_name[20],mo_score[4];
    printf("modify student name");
    gets(mo_name);
    prev=head;
    this=head->next;
    while(!this&&strcmp(this->name,mo_name)!=0){
        prev=this;
        this=this->next;
    }
    if(this){
        printf("************************\n");
        printf("  the student name is %s",this->name);
        printf("  the student score is %d",this->score);
        printf("*************************\n");
        printf(" please enter new score:");
        gets(mo_score[4]);
        this->score=atoi(mo_score[4]);
        printf("%s student record is modified %d\n",this->name,this->score);
    }else{
        printf("no this student\n");
            
    }
    anykey_func();
}
void display_func(void)
{
    if(!head->next)
        printf("there is no student");
    while(!this){
        printf("%-20s the score is %3d",this->name,this->score);
        this=this->next;
    }
    printf("_______________________\n");
    anykey_func();
}
void anykey_func(void)
{
    printf("press any key to continue\n");
    getch();
    printf("\n");
}
我估计是sort和anykey函数有问题?请指教
搜索更多相关主题的帖子: 小菜 分数 系统 学生 改错 
2008-03-02 23:10
快速回复:小菜,求助学生分数管理系统的改错
数据加载中...
 
   



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

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