| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2562 人关注过本帖
标题:求大神:帮我看看哪里出错了。提示:.exe 文件已停止工作(出现一个问题)
只看楼主 加入收藏
幸运的杨震
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-7-10
结帖率:0
收藏
已结贴  问题点数:10 回复次数:2 
求大神:帮我看看哪里出错了。提示:.exe 文件已停止工作(出现一个问题)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student
{
    int num;
    char name[20];
    int sex;
    int bir;
    char college[50];
    char degree[20];
    struct student *next;
};
#define LEN sizeof(struct student)
struct student *creat()//创建链表
{
    struct student *head=NULL;
    return head;
}
struct student *insert(struct student *head)//插入结点
{
    struct student *p0,*p1,*p2;
    p0=(struct student *)malloc(LEN);
    p0->next=NULL;
    printf("编号:");
    scanf("%d",&p0->num);
    printf("姓名:");
    scanf("%s",p0->name);
    printf("性别(男:1,女:2):");
    scanf("%d",&p0->sex);   
    printf("出生日期:");
    scanf("%d",&p0->bir);   
    printf("学院:");
    scanf("%s",p0->college);
    printf("学位(学士、硕士、博士in English):");
    scanf("%s",p0->degree);
    getchar();
    if(head==NULL)head=p0;
    else
    {
        p1=head;
        while((p0->num>p1->num)&&(p1->next!=NULL))
        {
            p2=p1;
            p1=p1->next;
        }
        if(p0->num<p1->num)
        {
            if(head==p1)
                head=p0;
            else p2->next=p0;
            p0->next=p1;
        }
        else p1->next=p0;
    }
        return (head);
}
struct student *del(struct student *head,int n)//删除
{
    struct student *p1,*p2=NULL;
    p1=head;
    while((n!=p1->num)&&(p1->next!=NULL))
    {
        p2=p1;
        p1=p1->next;
    }
    if(n==p1->num)
    {
        if(p1==head)head=p1->next;
        else p2->next=p1->next;
        free(p1);
        printf("已成功删除!\n");
    }
    else printf("不存在该学生!\n");
    return (head);
}
struct student *amend(struct student *head)//修改
{
    struct student *p1,*p2=NULL;
    int num;
    p1=head;
    printf("请输入要修改信息的学生编号:");
    scanf("%d",&num);
    while((num!=p1->num)&&(p1->next!=NULL))
    {
        p2=p1;
        p1=p1->next;
    }
    if(num==p1->num)
    {
        printf("请输入学生信息:\n");
        printf("编号:");
        scanf("%d",&p1->num);
    }
    else printf("不存在该学生!\n");
    return (head);
}
struct student *search(struct student *head)//查找
{
    struct student *p;
    p=head;
    int i,j,k;
    char ch[20];
    printf("请输入查询方式:(1.编号/2.姓名/3.学院\n");
    scanf("%d",&i);
    switch(i)
    {
    case 1:printf("请输入学生编号:");scanf("%d",&j);
           for(k=0;;k++)
           {
               if(p->num==j)
               {
                   printf("%s",p->name);
                   break;
               }
               if(p->next==NULL)break;
               p=p->next;
           }break;
    case 2:printf("请输入学生的姓名:");getchar();gets(ch);
           for(k=0;;k++)
           {
               if(strcmp(p->name,ch)==0)
               {
                   printf("%s",p->name);
                   break;
               }
               if(p->next==NULL)break;
               p=p->next;
           }break;
    case 3:printf("请输入学院名称:\n");getchar();gets(ch);
           for(k=0;;k++)
           {
               if(strcmp(p->college,ch)==0)
                   printf("%s",p->name);
               if(p->next==NULL)break;
               p=p->next;
           }break;
    default:printf("输入有误!\n");
    }
    return head;
}
void fun6(struct student *head)//统计
{
    struct student *p;
    int A=0,B=0,C=0,n=0,i;
    float m;
    p=head;
    for(i=1;;i++)
    {
        if(p->bir>=1990)n++;
        if(p->next==NULL)break;
        p=p->next;
    }
    printf("1990年以后出生的学生人数为%d\n",n);
    m=(float)n/i;//90后比例
    printf("90后学生所占比例为:%.2f\n",m);
   
    p=head;
    for(i=1;;i++)
    {
        if(strcmp(p->degree,"boshi")==0)A++;
        if(strcmp(p->degree,"shuoshi")==0)B++;
        if(strcmp(p->degree,"xueshi")==0)C++;
        if(p->next==NULL)break;
        p=p->next;
    }
    printf("博士人数为:%d\n硕士人数为:%d\n学士人数为:%d\n",A,B,C);
    m=(float)A/i;
    printf("博士学位的学生所占比例为:%.2f\n",m);
    //学位比例
}
void files(struct student *head)//文件
{
    struct student *p;
    int i=0;
    p=head;
    FILE *fp;
    if((fp=fopen("data.txt","w+"))==NULL)
    {
        printf("can't open file!\n");
        exit(0);
    }
    while(p!=NULL)
    {
        i++;
        p=p->next;
    }
    while(head!=NULL)
    {
        fwrite(p,LEN,i,fp);
        head=head->next;
    }
    printf("已保存至文件!\n");
    fclose(fp);
}
void list(struct student *head)//输出
{
    struct student *p;
    p=head;
    while(p!=NULL)
    {
        printf("%d",p->num);
        p=p->next;
    }
}
struct student *fun1(void)//fun1
{
    struct student *head;
    int n=3;
    char ch='y';
    head=creat();
    while(ch=='Y'||ch=='y')
    {
        head=insert(head);
        printf("继续输入?(y/n):");
        ch=getchar();
        getchar();
    }
    return head;
}
struct student *fun3(struct student *head)//fun3
{
    int n;
    char ch='y';
    while(ch=='Y'||ch=='y')
    {
        printf("请输入要删除信息的学生编号:");
        scanf("%d",&n);
        getchar();
        head=del(head,n);
        printf("继续删除?(y/n):");
        ch=getchar();
        getchar();
    }
    return head;
}
void main()
{
    struct student *head;
    int select;
    while(1)
    {
    printf("\n");
        printf("\t---------------------------------------------------------------\n");
        printf("\t*                                                             *\n");
        printf("\t* **********************   高校学生管理系统   *****************\n");
        printf("\t*                       学生学号:                            *\n");
        printf("\t*                       学生班级:                            *\n");
        printf("\t*                       学生姓名:                            *\n");
        printf("\t*                           感谢使用                          *\n");
        printf("\t--------------------------------------------------------------\n\n");
        printf("\t                       1.创建学生信息\n");
        printf("\t                       2.增加学生信息\n");
        printf("\t                       3.删除学生信息\n");
        printf("\t                       4.修改学生信息\n");
        printf("\t                       5.查询学生信息\n");
        printf("\t                       6.统计学生信息\n");
        printf("\t\n");
        printf("\t                    请选择功能按键0-6\n");
        scanf("%d",&select);
        getchar();
        switch(select)
        {
        case 1:head=fun1();
            files(head);break;
        case 2:head=insert(head);
            files(head);break;
        case 3:head=fun3(head);
            files(head);break;
        case 4:head=amend(head);
            files(head);break;
        case 5:search(head);break;
        case 6:fun6(head);break;
        default:printf("按键错误,请重新选择!\n");
        }
        list(head);
    }
}

[ 本帖最后由 幸运的杨震 于 2014-7-11 06:22 编辑 ]
搜索更多相关主题的帖子: insert include return college insert return include college insert return include college 
2014-07-10 17:42
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:5 
运行时出错就是程序错,不是“都没错”。

授人以渔,不授人以鱼。
2014-07-10 21:22
孤独一生
Rank: 2
来 自:四川达县
等 级:论坛游民
帖 子:45
专家分:55
注 册:2013-4-1
收藏
得分:5 
这种问题希望你不要发源代码因为源代码太长了没有时间帮你看找错误 发翻译器翻译的错误提示就可以了
2014-07-17 01:01
快速回复:求大神:帮我看看哪里出错了。提示:.exe 文件已停止工作(出现一个问 ...
数据加载中...
 
   



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

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