| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7252 人关注过本帖
标题:C语言运行时*.exe已停止工作 求帮助
只看楼主 加入收藏
tongdongdong
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-2-27
结帖率:0
收藏
已结贴  问题点数:10 回复次数:2 
C语言运行时*.exe已停止工作 求帮助
#include<stdio.h>
#include<string.h>
typedef struct student
{
    char sName[30];
    int id;
    int sMovtel;
    int home;
    char age[30];
    char dor[30];
}student;
int c;
void build();
void search();
void amend();
void change();
void input(student *p);
void output(student *p);
void sdele();
void cover();
int main()
{
    int admin, a, b = 1;
    char s;
    while (b == 1)
    {
        printf("********************是否以管理员身份登录**********************?(1是 OR 2否)");
        fflush(stdin);
        scanf("%d", &admin);
        switch (admin)
        {
        case 1:
            while (b == 1)
            {
                printf(" **************************************************************************\n");
                printf(" *                                                                        *\n");
                printf(" *                       欢迎使用学生通讯录管理系统                       *\n");
                printf(" *                                                                        *\n");
                printf(" **************************************************************************\n");
                printf("\t 1、信息输入    2、信息查询和统计     3、信息修改      4、信息删除   \n");
                printf("请选择.......\n");
                scanf("%d", &a);
                switch (a)
                {
                case 1:build(); break;
                case 2:search(); break;
                case 3:amend(); break;
                case 4:sdele(); break;

                }
                printf("是否返回主菜单('Y'or'N')\n");
                fflush(stdin);
                scanf("%c", &s);
                if (s == 'y' || s == 'Y')
                    b = 1;
                else
                    break;
            }
            break;
        case 2:
            while (b == 1)
            {
                printf("\t\t通讯录\n");
                printf("\t1、查找\n");
                printf("请选择.......\n");
                scanf("%d", &a);
                switch (a)
                {
                case 1:search(); break;
                }
                printf("是否返回主菜单('Y'or'N')\n");
                fflush(stdin);
                scanf("%c", &s);
                if (s == 'y' || s == 'Y')
                    b = 1;
                else
                    b = 2;
                break;
            }
            break;
        }
    }
    return 0;
}
/*信息输入*/
void build()
{
    int b = 1;
    char d;
    student x;
    FILE *fp = NULL;
    fp = fopen("e:\\通讯录.txt", "ab");
    while (b == 1)
    {
        input(&x);
        fwrite(&x, sizeof(x), 1, fp);
        printf("是否继续新建('Y'or'N')?\n");
        fflush(stdin);
        scanf("%c", &d);
        if (d == 'y' || d == 'Y')
        {
            b = 1;
        }
        else
            break;
    }
    fclose(fp);
}

/*查找*/
void search()
{
    int h, j = 1, n = 0, num, score;
    char k[20], sdor[20];
    FILE *fp = NULL;
    student y;
    printf("\t1、按电话号码查找\n");
    printf("\t2、按姓名查找\n");
    printf("\t3、按学生号查找\n");
    printf("\t4、按寝室号查找\n");
    printf("请选择...........\n");
    scanf("%d", &h);
    if (h == 1)
    {
        printf("\t请输入你查找的号码!\n");
        while (j == 1)
        {
            scanf("%d", &num);
            fp = fopen("e:\\通讯录.txt", "rb");
            while (!feof(fp))
            {
                fread(&y, sizeof(y), 1, fp);
                if (num == y.sMovtel)
                {
                    output(&y);
                    break;
                }
            }
            if (num != y.sMovtel)
            {
                printf("你输入的号码有误!!!\n请重新输入\n");
                j = 1;
            }
            fclose(fp);
        }
    }

    if (h == 2)
    {
        printf("\t请输入你查找的姓名!\n");
        while (j == 1)
        {

            scanf("%s", k);
            fp = fopen("e:\\通讯录.txt", "rb");
            while (!feof(fp))
            {
                fread(&y, sizeof(y), 1, fp);
                if (strcmp(k, y.sName) == 0)
                {
                    output(&y);
                    break;
                }
            }
            if (strcmp(k, y.sName) != 0)
            {
                printf("你输入的姓名有误!!!\n请重新输入\n");
                j = 1;
            }
            fclose(fp);
        }
    }
    if (h == 3)
    {
        printf("\t请输入你查找的学生号!\n");
        while (j == 1)
        {

            scanf("%d", &score);
            fp = fopen("e:\\通讯录.txt", "rb");
            while (!feof(fp))
            {
                fread(&y, sizeof(y), 1, fp);
                if (score == y.id)
                {
                    output(&y);
                    break;
                }
            }
            if (score != y.id)
            {
                printf("你输入的姓名有误!!!\n请重新输入\n");
                j = 1;
            }
            fclose(fp);
        }
    }
    if (h == 4)
    {
        printf("\t请输入你查找的姓名!\n");
        while (j == 1)
        {

            scanf("%s", sdor);
            fp = fopen("e:\\通讯录.txt", "rb");
            while (!feof(fp))
            {
                fread(&y, sizeof(y), 1, fp);
                if (strcmp(sdor, y.dor) == 0)
                {
                    output(&y);
                    break;
                }
            }
            if (strcmp(sdor, y.dor) != 0)
            {
                printf("你输入的姓名有误!!!\n请重新输入\n");
                j = 1;
            }
            fclose(fp);
        }
    }
}
/*修改*/
void amend()
{
    int h, j = 1, n = 0, num;
    char k[20];
    FILE *fp;
    student y;
    printf("\t1、按号码查找你所需要修改的原始资料\n");
    printf("\t2、按姓名查找你所需要修改的原始资料\n");
    printf("请选择...........\n");
    scanf("%d", &h);
    if (h == 1)
    {
        printf("\t请输入查找你的号码!\n");
        while (j == 1)
        {
            scanf("%d", &num);
            fp = fopen("e:\\通讯录.txt", "rb");
            while (!feof(fp))
            {
                c++;
                fread(&y, sizeof(y), 1, fp);
                if (num == y.sMovtel)
                {
                    change();
                    break;
                }
            }
            if (num != y.sMovtel)
            {
                printf("你输入的号码有误!!!\n请重新输入\n");
                j = 1;
            }
            fclose(fp);
        }
    }
    if (h == 2)
    {
        printf("\t请输入你查找的姓名!\n");
        while (j == 1)
        {
            c++;
            scanf("%s", k);
            fp = fopen("e:\\通讯录.txt", "rb");
            while (!feof(fp))
            {
                fread(&y, sizeof(y), 1, fp);
                if (strcmp(k, y.sName) == 0)
                {
                    change();
                    break;
                }
            }
            if (strcmp(k, y.sName) != 0)
            {
                printf("你输入的姓名有误!!!\n请重新输入\n");
                j = 1;
            }
            fclose(fp);
        }
    }
}
/*删除*/
void sdele()
{
    int h, j = 1, n = 0, num;
    char k[20];
    FILE *fp = NULL;
    student y;
    printf("\t1、按号码查找你所需要修改的原始资料\n");
    printf("\t2、按姓名查找你所需要修改的原始资料\n");
    printf("请选择...........\n");
    scanf("%d", &h);
    if (h == 1)
    {
        printf("\t请输入查找你的号码!\n");
        while (j == 1)
        {
            scanf("%d", &num);
            fp = fopen("e:\\通讯录.txt", "rb");
            while (!feof(fp))
            {
                fread(&y, sizeof(y), 1, fp);
                if (num == y.sMovtel)
                {
                    cover();
                    break;
                }
            }
            if (num != y.sMovtel)
            {
                printf("你输入的号码有误!!!\n请重新输入\n");
                j = 1;
            }
            fclose(fp);
        }
    }
    if (h == 2)
    {
        printf("\t请输入你查找的姓名!\n");
        while (j == 1)
        {
            scanf("%s", k);
            fp = fopen("e:\\通讯录.txt", "rb");
            while (!feof(fp))
            {
                fread(&y, sizeof(y), 1, fp);
                if (strcmp(k, y.sName) == 0)
                {
                    cover();
                    break;
                }
            }
            if (strcmp(k, y.sName) != 0)
            {
                printf("你输入的姓名有误!!!\n请重新输入\n");
                j = 1;
            }
            fclose(fp);
        }
    }
}
void change()/*用于修改*/
{
    int f, j;
    FILE *fp = NULL;
    student z;
    j = c * 133;
    printf("你要修改的内容:\n");
    printf("\t1、姓名\n\t2、固定电话号码\n\t3、学号\n");
    printf("\t4、年龄\n\t5、家庭住址、\n\t6、宿舍号\n");
    printf("请选择...........\n");
    scanf("%d", &f);
    printf("输入你的新信息!\n");
    switch (f)
    {
    case 1:fp = fopen("e:\\通讯录.txt", "wb");
        fread(&z, sizeof(z), 1, fp);
        fseek(fp, j, SEEK_SET);
        scanf("%s", z.sName);
        fwrite(&z.sName, sizeof(z.sName), 1, fp);
        fclose(fp);
        output(&z);
        break;
        fclose(fp);
    case 2:fp = fopen("e:\\通讯录.txt", "rb");
        fread(&z, sizeof(z), 1, fp);
        fseek(fp, (j + 31), SEEK_SET);
        scanf("%d", &z.sMovtel);
        fwrite(&z.sMovtel, sizeof(z.sMovtel), 1, fp);
        fclose(fp);
        break;
    case 3:fp = fopen("e:\\通讯录.txt", "rb");
        fread(&z, sizeof(z), 1, fp);
        fseek(fp, (j + 35), SEEK_SET);
        scanf("%d", &z.id);
        fwrite(&z.id, sizeof(z.id), 1, fp);
        fclose(fp);
    case 4:fp = fopen("e:\\通讯录.txt", "rb");
        fread(&z, sizeof(z), 1, fp);
        fseek(fp, (j + 73), SEEK_SET);
        scanf("%s", z.age);
        fwrite(&z.age, sizeof(z.age), 1, fp);
        fclose(fp);
        break;
    case 5:fp = fopen("e:\\通讯录.txt", "rb");
        fread(&z, sizeof(z), 1, fp);
        fseek(fp, (j + 69), SEEK_SET);
        scanf("%d", &z.home);
        fwrite(&z.home, sizeof(z.home), 1, fp);
        fclose(fp);
        break;
    case 6:fp = fopen("e:\\通讯录.txt", "rb");
        fread(&z, sizeof(z), 1, fp);
        fseek(fp, (j + 103), SEEK_SET);
        scanf("%d", &z.dor);
        fwrite(&z.dor, sizeof(z.dor), 1, fp);
        fclose(fp);
        break;
    }
}
void input(student *p)/*输入*/
{
    printf("请输入姓名:\n");
    scanf("%s", p->sName);
    printf("请输入手机号码:\n");
    scanf("%d", &p->sMovtel);
    printf("请输入学号:\n");
    scanf("%d", &p->id);
    printf("请输入年龄:\n");
    scanf("%s", p->age);
    printf("输入家庭住址");
    scanf("%s", p->home);
    printf("请输入宿舍号:\n");
    scanf("%s", p->dor);
}
void output(student *p)/*输出*/
{
    printf("**********************\n");
    printf("%s\n", p->sName);
    printf("%d\n", p->sMovtel);
    printf("%d\n", p->id);
    printf("%s\n", p->age);
    printf("%d\n", p->home);
    printf("%s\n", p->dor);
}
void cover()/*用于删除 */
{
    student d;
    FILE *fp = NULL;
    fp = fopen("e:\\通讯录.txt", "rb");
    fread(&d, sizeof(d), 1, fp);
}
搜索更多相关主题的帖子: include search change 管理员 admin 
2014-02-27 08:58
tongdongdong
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-2-27
收藏
得分:0 
按1输入信息时在输家庭住址那里出错,求帮助 在线等。
2014-02-27 09:01
klapset
Rank: 4
等 级:业余侠客
威 望:2
帖 子:71
专家分:234
注 册:2014-2-27
收藏
得分:10 
这个代码简单看了下,不仅粗糙,而且很不规整,更不要说编程结构,效率了。

出错估计是越界了。 使用scanf的时候第一个要小心的就是buffer的大小。另 不建议使用这个作为输入。
2014-02-27 18:39
快速回复:C语言运行时*.exe已停止工作 求帮助
数据加载中...
 
   



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

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