很简单的C语言程序,帮忙改下,急~~~

#include<stdio.h>
struct School
{int num;
int sumscore;
int item;
int score;
int sum;
char name[15];
}Sc[20];

struct Item
{
int Inum; //项目编号
int Iscore; //项目成绩
int all; //项目总数
}Pr[20];

School *g1;
Item *g2;

void Putscore() //输入成绩
{
int i,k;
School Sch;
Item Pro;

printf("输入学校总数n:");
scanf("%d",&Sch.sum);
while(Sch.sum<=0)
{
printf("输入错误,请重新输入。\n");
printf("输入学校总数n:");
scanf("%d",&Sch.sum);
}

printf("输入男子项目总数:");
scanf("%d",&Sch.man);
while(Sch.man<=0)
{
printf("输入错误,请重新输入。\n");
printf("输入男子项目总数:");
scanf("%d",&Sch.man);
}

printf("输入女子项目总数:");
scanf("%d",&Sch.woman);
while(Sch.woman<=0)
{
printf("输入错误,请重新输入。\n");
printf("输入女子项目总数:");
scanf("%d",&Sch.woman);
}

Pro.all=Sch.man+Sch.woman;

printf("输入项目编号,以-1作为结束:");
scanf("%d",&k);
while(k!=-1) //以-1为结束
{
printf("前三名按3,前五名按5.");
scanf("%d",&i);
if(i!=3&&i!=5)
{
printf("输入错误,请重新输入。");
printf("前三名按3,前五名按5.");
scanf("%d",&i);
}
if(i==3)
{
printf("获得第一名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=5;
printf("获得第二名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=3;
printf("获得第三名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=2;
}

if(i==5)
{
printf("获得第一名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=7;
printf("获得第二名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=5;
printf("获得第三名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=3;
printf("获得第四名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=2;
printf("获得第五名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=1;
}
printf("输入项目编号,以-1作为结束:");
scanf("%d",&k);
}
}

void save() //存储数据
{
FILE *fp;
int i;
if((fp=fopen("a1","wb"))==NULL)
{
printf("cannot open this file\n");
return;
}
for(i=0;i<20;i++)
if(fwrite(&Pr[i],sizeof(struct Item),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
void aa(School *g1,Item *g2)
{
Putscore() ;
save();
int i,j;
printf("请输入要查询学校编号:");
scanf("%d",&i);
if(i<=0)
{
printf("输入有误,请重新输入:");
scanf("%d",&i);
}
if(i>=20)
{
printf("输入有误,请重新输入:");
scanf("%d",&i);
}
//printf("请输入要查询的项目编号:");
//scanf("%d",&j);

for(j=0;j<20;j++)
{
if (i == Sc[j].num)
{
printf("num:%d score:%d\n",Sc[j].num,Sc[j].score);
}
}
//if(i==sch.num)
//{ printf("%d",pro.pscore);
//}

}

void main()
{
Putscore();
save();
aa(School *g1,Item *g2);
}

第1个回答  推荐于2016-05-12
void Input()
{ int item=1;
int i;
int k;
int temp1,flag=0;
char ch;
int temp[6];
do
{
loop: for(k=1;k<6;k++)
temp[k]=0;
do
{
if((item>(W+M))||(item<1)) printf("\n输入错误!再次输入!\n");
printf("项目代码(男子取前五名,女子取前三名):\n");
scanf("%d",&item);
}
while((item>(W+M))||(item<1));
printf("项目名称:");
scanf("%s",iteM[item].Iname);
if((item>0)&&(item<=M))
{
printf("\n男子项目%d的前五名学校代码:",item);
for(i=1;i<6;i++)
{
do
{
printf("第%d名学校代码:",i); scanf("%d",&temp1);
printf("第%d名学校名称:",i); scanf("%s",&name[temp1]);
flag=0;
for(k=0;k<6;k++)
if(i!=k)
if((temp1==temp[k])||((temp1<1)||(temp1>N))) {printf("输入错误!重新输入! \n");flag=1; break;
}
temp[i]=temp1;
}
while(flag!=0);
iteM[item].man[i]=temp1;
sch[temp1].man[item]=item;
switch(i)
{
case 1: sch[temp1].scoreT+=7; sch[temp1].scoreM+=7;break;
case 2: sch[temp1].scoreT+=5; sch[temp1].scoreM+=5;break;
case 3: sch[temp1].scoreT+=3; sch[temp1].scoreM+=3;break;
case 4: sch[temp1].scoreT+=2; sch[temp1].scoreM+=2;break;
case 5: sch[temp1].scoreT+=1; sch[temp1].scoreM+=1;break;}
}
}
else if((item>M)&&(item<=(M+W)))
{
printf("\n女子项目%d的前五名学校代码:",item);
for(i=1;i<4;i++)
{
do
{
printf("第%d名学校代码:",i); scanf("%d",&temp1);
printf("第%d名学校名称:",i); scanf("%s",&name[temp1]);
flag=0;
for(k=0;k<6;k++)
if(i!=k)
if((temp1==temp[k])||((temp1<1)||(temp1>N))) {printf("输入错误!重新输入!\n");flag=1; break;}
temp[i]=temp1;
}
while(flag!=0);
iteM[item].women[i]=temp1;
sch[temp1].women[item]=item;

switch(i)
{case 1: sch[temp1].scoreT+=5; sch[temp1].scoreW+=5;break;
case 2: sch[temp1].scoreT+=3; sch[temp1].scoreW+=3;break;
case 3: sch[temp1].scoreT+=2; sch[temp1].scoreW+=2;break;}
}
}
else if((item<=0)||(item>M+W)) {printf("输入错误!再次输入!\n");goto loop;}
printf("\n再次输入?(Y/N):");
ch=getch(); printf("\n");
}while((ch=='Y')||(ch=='y'));

}本回答被提问者采纳
第2个回答  2010-06-22
改好了……

#include<stdio.h>
struct _School
{int num;
int sumscore;
int item;
int score;
int sum;
char name[15];
int man;
int woman;
}Sc[20];

typedef struct _School School;

struct _Item
{
int Inum; //项目编号
int Iscore; //项目成绩
int all; //项目总数
}Pr[20];

typedef struct _Item Item;

School *g1;
Item *g2;

void Putscore() //输入成绩
{
int i,k;
School Sch;
Item Pro;

printf("输入学校总数n:");
scanf("%d",&Sch.sum);
while(Sch.sum<=0)
{
printf("输入错误,请重新输入。\n");
printf("输入学校总数n:");
scanf("%d",&Sch.sum);
}

printf("输入男子项目总数:");
scanf("%d",&Sch.man);
while(Sch.man<=0)
{
printf("输入错误,请重新输入。\n");
printf("输入男子项目总数:");
scanf("%d",&Sch.man);
}

printf("输入女子项目总数:");
scanf("%d",&Sch.woman);
while(Sch.woman<=0)
{
printf("输入错误,请重新输入。\n");
printf("输入女子项目总数:");
scanf("%d",&Sch.woman);
}

Pro.all=Sch.man+Sch.woman;

printf("输入项目编号,以-1作为结束:");
scanf("%d",&k);
while(k!=-1) //以-1为结束
{
printf("前三名按3,前五名按5.");
scanf("%d",&i);
if(i!=3&&i!=5)
{
printf("输入错误,请重新输入。");
printf("前三名按3,前五名按5.");
scanf("%d",&i);
}
if(i==3)
{
printf("获得第一名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=5;
printf("获得第二名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=3;
printf("获得第三名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=2;
}

if(i==5)
{
printf("获得第一名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=7;
printf("获得第二名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=5;
printf("获得第三名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=3;
printf("获得第四名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=2;
printf("获得第五名的学校编号:");
scanf("%d",&Pro.Inum);
Pr[Pro.Inum].Iscore=1;
}
printf("输入项目编号,以-1作为结束:");
scanf("%d",&k);
}
}

void save() //存储数据
{
FILE *fp;
int i;
if((fp=fopen("a1","wb"))==NULL)
{
printf("cannot open this file\n");
return;
}
for(i=0;i<20;i++)
if(fwrite(&Pr[i],sizeof(Item),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}

void aa(School *g1,Item *g2)
{
int i,j;
printf("请输入要查询学校编号:");
scanf("%d",&i);
if(i<=0)
{
printf("输入有误,请重新输入:");
scanf("%d",&i);
}
if(i>=20)
{
printf("输入有误,请重新输入:");
scanf("%d",&i);
}
//printf("请输入要查询的项目编号:");
//scanf("%d",&j);

for(j=0;j<20;j++)
{
if (i == Sc[j].num)
{
printf("num:%d score:%d\n",Sc[j].num,Sc[j].score);
}
}
//if(i==sch.num)
//{ printf("%d",pro.pscore);
//}

}

void main()
{
Putscore();
save();
aa(g1, g2);
}
相似回答