输入十组数据后,出现0xC0000005: Access violation,不知何故?请问应如何修改?谢谢
此程序是为了完成严蔚敏的数据结构与算法的题目1.18[img=http://static13.photo.sina.com.cn/middle/61d68be8x79ca4df06dec&690][/img]
程序如下:
#include<stdio.h>
#include<conio.h>
typedef struct //定义数据类型
{
char sport;
enum{male,female} gender; //枚举类型
char schoolname;
char resultx; //成绩
int score;
} resulttype;
resulttype result[1000];
typedef struct
{
int malescore;
int femalescore;
int totalscore;
} scoretype;
void input(void) //INPUT函数
{ int i;
i=0;
do{
printf("请输入数据sport, gender,schoolname,resultx,score\n");
scanf("%s\n%s\n%c\n%s\n%d",&result[i].sport,&result[i].gender,&result[i].schoolname,&result[i].resultx, &result[i].score);
i++;
}while(i<10);
}
void output(void) //OUTPUT函数
{
int i;
for(i = 0; i<10; i++)
{
printf("%s %s %c %s %d",result[i].sport, result[i].gender, result[i].schoolname,result[i].resultx, &result[i].score);
}
}
void summary(resulttype result[ ]) //统计函数
{
int i;
scoretype score;
i=0;
while(result[i].sport!=NULL)
{
switch(result[i].schoolname)
{
case 'A':
score.totalscore+=result[i].score;
if(result[i].gender==0) score.malescore+=result[i].score;
else score.femalescore+=result[i].score;
break;
case 'B':
score.totalscore+=result[i].score;
if(result[i].gender==0) score.malescore+=result[i].score;
else score.femalescore+=result[i].score;
break;
case 'C':
score.totalscore+=result[i].score;
if(result[i].gender==0) score.malescore+=result[i].score;
else score.femalescore+=result[i].score;
break;
case 'D':
score.totalscore+=result[i].score;
if(result[i].gender==0) score.malescore+=result[i].score;
else score.femalescore+=result[i].score;
break;
case 'E':
score.totalscore+=result[i].score;
if(result[i].gender==0) score.malescore+=result[i].score;
else score.femalescore+=result[i].score;
break;
}
i++;
}
for(i=0;i<5;i++)
{
printf("School %d:\n",i);
printf("Total score of male:%d\n",score.malescore);
printf("Total score of female:%d\n",score.femalescore);
printf("Total score of all:%d\n\n",score.totalscore);
}
}
main()
{
input();
output();
getch();
}
--------------------Configuration: 1.18 - Win32 Debug--------------------
Compiling...
1.18.c
G:\1.18.c(46) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'void *'
1.18.obj - 0 error(s), 1 warning(s) --------------------编程问答-------------------- 放错位置了。。。
是非法操作错误 --------------------编程问答-------------------- 哥哥,和没回答一样
补充:.NET技术 , C#