| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 753 人关注过本帖
标题:求助,大神帮看看这个运行起来怎么提示内存不能read
只看楼主 加入收藏
s289436620
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-1-12
结帖率:0
收藏
已结贴  问题点数:20 回复次数:17 
求助,大神帮看看这个运行起来怎么提示内存不能read
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define COUNT 100

void init(void);
void input(void);
void count(void);
void brow(void);

struct student
{
int num;
int age;
char sex[4];
char name[10];  
int score1;
int score2;
int score3;
int score4;
char score5;  
float zf;
}
st[COUNT];
int sm;
void main()
{
int x;        
init();
do
{  
printf("\t\t\t  学生成绩管理系统  \t\t\t\n");  
printf("\t\t1:__________输入\n");  
printf("\t\t2:__________浏览\n");               
printf("\t\t3:__________统计\n");  
printf("\t\t0:__________退出\n");  
printf("请输入你的选择:");  
scanf("%d", &x);  
switch(x)
{  
case 1:   input();   break;  
case 2:   brow();   break;  
case 3:                        count();   break;  
case 0:   printf("谢谢使用,再见\n");   break;  
}
} while (x != 0);        
return ;
}
void init(void)
{
memset(st,0,sizeof(st));
sm = 0;
}
void input(void)
{ int i, n, t, j;
printf("请输入学生数量:");
scanf("%d", &n);        
sm = n;
for (i = 0;i < n; i++)
{  
printf("请输入第%d个学生的成绩:\n",i+1);  
printf("请输入学号:");
fflush(stdin);  
scanf("%d", &st[i].num);
printf("请输入年龄:");
scanf("%d",&st[i].age);
printf("请输入性别:");
scanf("%s",st[i].sex);  
for (t = 0; t < i; t++)
{   
    if (st[i].num == st[t].num)                        
{           
printf("该学生的学号已存在,请重新输入!\n");                                
fflush(stdin);           
scanf("%d", &st[i].num);           
t = 0;                        
}  
}
                  
printf("请输入姓名:");  
scanf("%s", st[i].name);
printf("请输入数学分析成绩:");  
scanf("%d", &st[i].score1);  
printf("请输入高等代数成绩:");  
scanf("%d", &st[i].score2);  
printf("请输入英语成绩:");  
scanf("%d", &st[i].score3);  
printf("请输入概率统计成绩:");  
scanf("%d", &st[i].score4);  
printf("请输入体育成绩:");  
scanf("%s", &st[i].score5);
}
}
void count(void)
{
int i;
for (i = 0; i < sm; i++)
{
if (st[i].score5=='优')
    st[i].score5=90;
    else if(st[i].score5=='良')
        st[i].score5=80;
    else if(st[i].score5=='中')
        st[i].score5=70;
    else if(st[i].score5=='及')
        st[i].score5=60;
    else if(st[i].score5=='差')
        st[i].score5=50;
st[i].zf = 0;  
st[i].zf = st[i].score1 + st[i].score2 + st[i].score3 + st[i] .score4 + st[i].score5;
printf("第%d位学生的总成绩为%f",i+1,st[i].zf);
}
}
void brow(void)
{
int i;
for (i = 0; i < sm; i++)
{  
printf("第%d个学生信息\n", i + 1);
printf("学号:%4d\n", st[i].num);  
printf("姓名:%s\n", st[i].name);  
printf("性别:%s\n", st[i].sex);  
printf("年龄:%d\n", st[i].age);  
printf("第一门成绩:%d\n", st[i].score1);  
printf("第二门成绩:%d\n", st[i].score2);  
printf("第三门成绩:%d\n", st[i].score3);  
printf("第四门成绩:%d\n", st[i].score4);  
printf("第五门成绩:%s\n", st[i].score5);  
printf("\n");
}
}

详细运行结果见6楼

[ 本帖最后由 s289436620 于 2013-1-12 11:01 编辑 ]
搜索更多相关主题的帖子: count 管理系统 include 
2013-01-12 10:20
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:3 
把报错的图片贴出来看看啊,
这样错误通常是空指针的引用或者内存溢出造成的

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2013-01-12 10:28
浅水无殇
Rank: 2
等 级:论坛游民
帖 子:123
专家分:75
注 册:2012-11-23
收藏
得分:3 
我运行了一下。。。貌似还好啊。。。不过有时候我会遇到名为非法访问内存的错误。。实际上,算法没错,编译也过了,就是一运行就出毛病。。这种有具体原因么?

wula wual
2013-01-12 10:35
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:3 
以下是引用浅水无殇在2013-1-12 10:35:44的发言:

我运行了一下。。。貌似还好啊。。。不过有时候我会遇到名为非法访问内存的错误。。实际上,算法没错,编译也过了,就是一运行就出毛病。。这种有具体原因么?

出了毛病还说没错?

授人以渔,不授人以鱼。
2013-01-12 10:38
浅水无殇
Rank: 2
等 级:论坛游民
帖 子:123
专家分:75
注 册:2012-11-23
收藏
得分:0 
呦。。发现问题啦。。。。这种就是非法访问内存吧。。

wula wual
2013-01-12 10:39
s289436620
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-1-12
收藏
得分:0 
                          学生成绩管理系统
                1:__________输入
                2:__________浏览
                3:__________统计
                0:__________退出
请输入你的选择:1
请输入学生数量:1
请输入第1个学生的成绩:
请输入学号:123
请输入年龄:25
请输入性别:男
请输入姓名:单
请输入数学分析成绩:90
请输入高等代数成绩:90
请输入英语成绩:90
请输入概率统计成绩:90
请输入体育成绩:优
                          学生成绩管理系统
                1:__________输入
                2:__________浏览
                3:__________统计
                0:__________退出
请输入你的选择:3
第1位学生的总成绩为315.000000                     学生成绩管理系统

                1:__________输入
                2:__________浏览
                3:__________统计
                0:__________退出
请输入你的选择:2
第1个学生信息
学号: 123
姓名:单
性别:男
年龄:25
第一门成绩:90
第二门成绩:90
第三门成绩:90
第四门成绩:90
 
运行时总分计算不正确。选择浏览时不显示第五门成绩,并提示内  什么指令应用的什么内存,该内存不能为read
2013-01-12 11:00
s289436620
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-1-12
收藏
得分:0 
回复 2楼 yaobao
麻烦看下6楼
2013-01-12 11:02
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:3 
st[i].score5=='优'

总有那身价贱的人给作业贴回复完整的代码
2013-01-12 11:56
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:3 
代码都好长啊
2013-01-12 11:57
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:0 
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define COUNT 100

void init(void);
void input(void);
void count(void);
void brow(void); 

struct student
{
int num;
int age;
char sex[4];
char name[10]; 
int score1;
int score2;
int score3;
int score4;
char score5[4];
int  score5_;
float zf;
}
st[COUNT];
int sm;
void main()
{
int x;       
init();
do
{ 
printf("\t\t\t  学生成绩管理系统  \t\t\t\n"); 
printf("\t\t1:__________输入\n"); 
printf("\t\t2:__________浏览\n");               
printf("\t\t3:__________统计\n"); 
printf("\t\t0:__________退出\n"); 
printf("请输入你的选择:"); 
scanf("%d", &x); 
switch(x)
{ 
case 1:   input();   break; 
case 2:   brow();   break; 
case 3:                        count();   break; 
case 0:   printf("谢谢使用,再见\n");   break; 
}
} while (x != 0);       
return ;
}
void init(void)
{
memset(st,0,sizeof(st));
sm = 0;
}
void input(void)
{ int i, n, t, j;
printf("请输入学生数量:");
scanf("%d", &n);       
sm = n;
for (i = 0;i < n; i++)
{ 
printf("请输入第%d个学生的成绩:\n",i+1); 
printf("请输入学号:");
fflush(stdin); 
scanf("%d", &st[i].num);
printf("请输入年龄:");
scanf("%d",&st[i].age);
printf("请输入性别:");
scanf("%s",st[i].sex); 
for (t = 0; t < i; t++)
{  
    if (st[i].num == st[t].num)                       
{          
printf("该学生的学号已存在,请重新输入!\n");                               
fflush(stdin);          
scanf("%d", &st[i].num);          
t = 0;                       
} 
}
                 
printf("请输入姓名:"); 
scanf("%s", st[i].name);
printf("请输入数学分析成绩:"); 
scanf("%d", &st[i].score1); 
printf("请输入高等代数成绩:"); 
scanf("%d", &st[i].score2); 
printf("请输入英语成绩:"); 
scanf("%d", &st[i].score3); 
printf("请输入概率统计成绩:"); 
scanf("%d", &st[i].score4); 
printf("请输入体育成绩:"); 
scanf("%s", st[i].score5);
}
}
void count(void)
{
int i;
for (i = 0; i < sm; i++)
{
if (st[i].score5=="")
    st[i].score5_=90;
    else if(st[i].score5=="")
        st[i].score5_=80;
    else if(st[i].score5=="")
        st[i].score5_=70;
    else if(st[i].score5=="")
        st[i].score5_=60;
    else if(st[i].score5=="")
        st[i].score5_=50;
st[i].zf = 0; 
st[i].zf = st[i].score1 + st[i].score2 + st[i].score3 + st[i] .score4 + st[i].score5_;
printf("第%d位学生的总成绩为%f",i+1,st[i].zf);
}
}
void brow(void)
{
int i;
for (i = 0; i < sm; i++)
{ 
printf("第%d个学生信息\n", i + 1);
printf("学号:%4d\n", st[i].num); 
printf("姓名:%s\n", st[i].name); 
printf("性别:%s\n", st[i].sex); 
printf("年龄:%d\n", st[i].age); 
printf("第一门成绩:%d\n", st[i].score1); 
printf("第二门成绩:%d\n", st[i].score2); 
printf("第三门成绩:%d\n", st[i].score3); 
printf("第四门成绩:%d\n", st[i].score4); 
printf("第五门成绩:%s\n", st[i].score5); 
printf("\n");
}
}

小手一钩,分数到手,拎起酱油,转头猛走。
代码如上,楼主看看合不合心意,吃着好再说。

[ 本帖最后由 yaobao 于 2013-1-12 12:05 编辑 ]

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2013-01-12 12:01
快速回复:求助,大神帮看看这个运行起来怎么提示内存不能read
数据加载中...
 
   



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

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