| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4322 人关注过本帖
标题:在用C语言编写程序的时候,编译通过,但是运行的时候出现应用程序错误
取消只看楼主 加入收藏
d398654
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-12-28
收藏
 问题点数:0 回复次数:5 
在用C语言编写程序的时候,编译通过,但是运行的时候出现应用程序错误
RT,一般是会是什么问题产生的。我检查过好多遍了
搜索更多相关主题的帖子: 编写程序 检查 应用程序 C语言 
2011-12-28 11:25
d398654
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-12-28
收藏
得分:0 
void search()
{
stu *p2;
    int nums[10];
    int b=0;
    printf("Enter the num of the student you want to find:");/*通过学号查看*/
    scanf("%s",&nums);
    while(p2!=NULL)
    {
        if(nums==p2->num)
        {
            printf("The data you want has be found\n");
            printf(" Name:%s\t",p2->name);
            printf("Num:%d\t",p2->num);
            printf("sex%s\t",p2->sex);
            printf("\n");
            printf("Chinese:%d\t",p2->chinese);
            printf("Math:%d\t",p2->mathematic);
            printf("English:%d\t",p2->english);
            printf("Computer:%d\t",p2->computer);
            printf("\n");
            b=1;
        }
        else if(b==0)
        {
            printf("sorry not find data!");
            p2=p2->next;
        }
        if(b==1)
        {
            print();
            printf("Find one\n");
        }
        else
        {
            print();
            printf("Not find\n");
        }
    }
}
我个人觉得是这里面有问题,找好久没找到
2011-12-28 11:26
d398654
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-12-28
收藏
得分:0 
回复 3楼 embed_xuel
那要怎么来改?
2011-12-28 12:06
d398654
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-12-28
收藏
得分:0 
我把全部的贴出来吧,我还得改的。#include<stdio.h>              


#include<dos.h>
#include<string.h>
#include "stddef.h"
#include <stdlib.h>
//#include "stdafx.h"
#include <conio.h>
#define MAX 10
typedef struct student /*定义结构体*/
{
    char name[MAX]; /*姓名*/
    int num[MAX]; /* 学号*/
    char sex[MAX]; /*性别*/
    float chinese; /*语文*/
    float mathematic; /* 数学*/
    float english; /*英语*/
    float computer; /*计算机*/
    struct student *next; /*结构体指针*/
}stu;
stu *head;

void cin(stu *p1) /*输入相关数据的函数*/
{
    printf("Enter name:\n");
    scanf("%s",&p1->name);
    printf("Enter num:\n");
    scanf("%d",&p1->num);
    printf("Enter sex:\n");
    scanf("%s",&p1->sex);
    printf("Enter score:\n");
    printf("Enter chinese:\n");
    scanf("%d",&p1->chinese);
    printf("Enter math:\n");
    scanf("%d",&p1->mathematic);
    printf("Enter English:\n");
    scanf("%d",&p1->english);
    printf("Enter Computer:\n");
    scanf("%d",&p1->computer);
}
stu *cindata() /*其他数据是否继续输入的函数*/
{
    stu *p1,*p2;
    int i=1;
    char ch;
    p1=(stu *)malloc(sizeof(stu));
    head=p1;
    while(i)
    {
        cin(p1);
        printf("Do you Want to Continue?yes or no"); /*是否继续输入数据*/
        ch=getchar();
        ch=getchar();
        if(ch=='n'||ch=='N')
        {
            i=0;
            p1->next=NULL;
        }
        else
        {
            p2=p1;
            p1=(stu *)malloc(sizeof(stu));
            p2->next=p1;
        }
    }
    return(p1->next);
}

/*自定义print()函数,实现菜单选择功能*/
void print()
{
   system("cls");
   printf("\n\n\n\n\n");
   printf("\t\t|                     STUDENT                  |\n");
   printf("\t\t|\t0.退出系统                                |\n");
   printf("\t\t|\t1.输入记录                                |\n");
   printf("\t\t|\t2.查询记录                                |\n");
   printf("\t\t|\t3.新生插入                                |\n");
   printf("\t\t|\t4.显示所有                                |\n");
   printf("\t\t|                                              |\n");
   printf("\t\t\tchoose(0-4):");
}
void insert() /*通过比较学号来插入数据的函数*/
{
    stu *p1,*p3,*p2;
    p1=head;
    p3=(stu *)malloc(sizeof(stu));
    p3->next=NULL;
    if(head==NULL){ head=p3; return;}
    cin(p3);
    while(p1!=NULL&&(p1->num<p3->num))
    {  /*通过学号的比较来插入*/
        p2=p1;p1=p1->next;
    }
    if(p2==head) {p3->next=head; head=p3; return;}
    p3->next=p1;
    p2->next=p3;
}
void search()
{
stu *p2;
    int nums[10];
    int b=0;
    printf("Enter the num of the student you want to find:");/*通过学号查看*/   
    scanf("%s",&nums);
    while(p2!=NULL)
    {
        if(nums==p2->num)
        {
            printf("The data you want has be found\n");
            printf(" Name:%s\t",p2->name);
            printf("Num:%d\t",p2->num);
            printf("sex%s\t",p2->sex);
            printf("\n");
            printf("Chinese:%d\t",p2->chinese);
            printf("Math:%d\t",p2->mathematic);
            printf("English:%d\t",p2->english);
            printf("Computer:%d\t",p2->computer);
            printf("\n");
            b=1;
        }
        else if(b==0)
        {
            printf("sorry not find data!");
            p2=p2->next;
        }
        if(b==1)
        {
            print();
            printf("Find one\n");
        }
        else
        {
            print();
            printf("Not find\n");
        }
    }
}

void caverage() /*求各学生语文平均分、最高和最低分成绩的函数*/
{
    stu *p1;
    int i;
    float max=0.0,min=200.0;
    float sum=0.0,aver=0;
    p1=head;
    if(p1==NULL)
        printf("not data!");
    else
    {
        for(i=0;p1!=NULL;i++,p1=p1->next)
            sum+=p1->chinese;
        aver=sum/i;
        p1=head;
        for(i=0;p1!=NULL;i++,p1=p1->next)
        {
            if(max<p1->chinese)
                max=p1->chinese;
        }
        p1=head;
        for(i=0;p1!=NULL;i++,p1=p1->next)
            if(min>p1->chinese)
                min=p1->chinese;
    }
    printf("Chinese Average:%f",aver);
    printf("Chinese Max:%f",max);
    printf("Chinese Min:%f",min);
}


void maverage() /*求各学生数学平均分、最高和最低分成绩的函数*/
{
    stu *p1;
    int i;
    float max=0.0,min=200.0;
    float sum=0.0,aver=0;
    p1=head;
    if(p1==NULL)
        printf("not data!");
    else
    {
        for(i=0;p1!=NULL;i++,p1=p1->next)
            sum+=p1->mathematic;
        aver=sum/i;
        p1=head;
        for(i=0;p1!=NULL;i++,p1=p1->next)
        {
            if(max<p1->mathematic)
                max=p1->mathematic;
        }
        p1=head;
        for(i=0;p1!=NULL;i++,p1=p1->next)
            if(min>p1->mathematic)
                min=p1->mathematic;
    }
    printf("Mathe Average:%f",aver);
    printf("Mathe Max:%f",max);
    printf("Mathe Min:%f",min);
}

void eaverage() /*求各学生英语平均分、最高和最低分成绩的函数*/
{
    stu *p1;
    int i;
    float max=0.0,min=200.0;
    float sum=0.0,aver=0;
    p1=head;
    if(p1==NULL)
        printf("not data!");
    else
    {
        for(i=0;p1!=NULL;i++,p1=p1->next)
            sum+=p1->english;
        aver=sum/i;
        p1=head;
        for(i=0;p1!=NULL;i++,p1=p1->next)
        {
            if(max<p1->english)
                max=p1->english;
        }
        p1=head;
        for(i=0;p1!=NULL;i++,p1=p1->next)
            if(min>p1->english)
                min=p1->english;
    }
    printf("English Average:%f",aver);
    printf("English Max:%f",max);
    printf("English Min:%f",min);
}

void comaverage() /*求各学生计算机平均分、最高和最低分成绩的函数*/
{
    stu *p1;
    int i;
    float max=0.0,min=200.0;
    float sum=0.0,aver=0;
    p1=head;
    if(p1==NULL)
        printf("not data!");
    else
    {
        for(i=0;p1!=NULL;i++,p1=p1->next)
            sum+=p1->computer;
        aver=sum/i;
        p1=head;
        for(i=0;p1!=NULL;i++,p1=p1->next)
        {
            if(max<p1->computer)
                max=p1->computer;
        }
        p1=head;
        for(i=0;p1!=NULL;i++,p1=p1->next)
            if(min>p1->computer)
                min=p1->computer;
    }
    printf("Computer Average:%f",aver);
    printf("Computer Max:%f",max);
    printf("Computer Min:%f",min);
}

/*自定义Showsystem()函数,实现打印系统的主界面输出*/
void Showsystem()
{
system("cls");                   /*清屏*/
/*打印系统主界面*/
printf("#=================================================================#\n");
printf("#=================================================================#\n");
printf("#                      欢迎使用学生成绩管理系统!                  #\n");
printf("#-----------------------------------------------------------------#\n");
printf("#                         copyright @ 2010-7-1                    #\n");
printf("#=================================================================#\n");
}/*Showsystem()函数结束*/

void main()
{
   int n;
   Showsystem(); /*按系统界面  */
   getch();
   print();
   scanf("%d",&n);
   while(n)
   {
       switch(n)
       {
           case 1:
                cin(head);
                break;
           case 2:
                search();
                break;
           case 3:
                insert();
                break;
           default:
                break;
       }
 
       print();
       scanf("%d",&n);
    }
}
里面的search函数,我还得改,没查询到学号的输出平均分,最高和最低分。
2011-12-28 12:45
d398654
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-12-28
收藏
得分:0 
回复 6楼 TonyDeng
要求是,输入学号查询,查询到则输出;查询不到就显示其他的。。。
2011-12-28 12:50
d398654
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-12-28
收藏
得分:0 
回复 8楼 于祥
昨天有用C++写,但是发现不合要求,所以今天又改,发现还是问题多多。出现的内存引用错误百度都搜不到为什么。
2011-12-28 12:51
快速回复:在用C语言编写程序的时候,编译通过,但是运行的时候出现应用程序错误
数据加载中...
 
   



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

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