#include"stdio.h"
struct xinxi
{
char name[20];
char yuanxi[20];
long num;
int xiangmu;
int mingci;
};
struct xinxi a[50];
struct xinxi p;
void shuru()
{
int i;
char c;
for(i=0;i<50;i++)
{
printf("qing shu ru bi sai xiang mu bian hao\n");
scanf("%d",&a[i].xiangmu);
printf("\n name:\n");
scanf("%s",a[i].name);
printf("\n yuanxi \n");
scanf("%s",a[i].yuanxi);
printf("\n xuehao \n");
scanf("%ld",&a[i].num);
printf("\n ming ci \n");
scanf("%d",&a[i].mingci);
printf("\n continue yes or no? xie y|n\n");
scanf("%c",&c);
scanf("%c",&c);
if(c=='y') continue;
if(c=='n') break;
}
}
void chazhao()
{
int i,j;
long b;
printf("qing shu ru chao zhao de xue hao(0=tiaochu)\n");
scanf("%ld",&b);
printf("\n xiang mu \n");
scanf("%d",&j);
while(b!=0)
{
for(i=0;i<50;i++)
{
if(a[i].num==b&&a[i].xiangmu==j)
printf("xing ming :%s\n",a[i].name);
printf("yuan xi :%s\n",a[i].yuanxi);
printf("xiang mu :%d\n",a[i].xiangmu);
printf("xue hao: %ld\n",a[i].num);
printf("ming ci :%d\n",a[i].mingci);
}
printf("\n qing shu ru chao zhao de xue hao(0=tiaochu)\n");
scanf("%ld",&b);
printf("\n xiang mu \n");
scanf("%d",&j);
}
}
void cunchu(int n)
{
int i,j,k,h;
FILE *fw;
fw=fopen("D:\hujian.txt","w");
for(k=1;k<=n;k++)
{
printf("di %d xiang bi sai de ji lu\n",k);
fprintf(fw,"di %d xiang bi sai de ji lu\n",k);
for(h=0;h<50;h++)
{
if(a[h].xiangmu==k)
{
for(i=1;i<50;i++)
for(j=0;j<50-i;j++)
{
if(a[j].mingci>a[j+1].mingci)
{
p=a[j];a[j]=a[j+1];a[j+1]=p;
}
}
for(i=0;i<3;i++)
{
printf("%10s %10s %10ld %10d\n",a[i].name,a[i].yuanxi,a[i].num,a[i].mingci);
fprintf(fw,"%10s %10s %10ld %10d\n",a[i].name,a[i].yuanxi,a[i].num,a[i].mingci);
}
}}}
fclose(fw);
}
void shanchu(int n)
{
long b;
int a1,h,j,i,k;
FILE *fw;
fw=fopen("D:\\hujian.txt","w");
printf("qing shu ru xue hao\n");
scanf("%ld",&b);
printf("\n xiang mu \n");
scanf("%d",&a1);
for(h=0;h<50;h++)
{
if(a[h].num==b&&a[h].xiangmu==a1)
{
for(k=1;k<=n;k++)
{
fprintf(fw,"di %d xiang bi sai de ji lu\n",k);
for(i=1;i<50;i++)
for(j=0;j<50-i;j++)
{
if(a[j].mingci>a[j+1].mingci)
{
p=a[j];a[j]=a[j+1];a[j+1]=p;
}
}
for(i=h;i<50;i++)
a[i+1]=a[i];
for(i=0;i<3;i++)
{
fprintf(fw,"%10s %10s %10ld %10d\n",a[i].name,a[i].yuanxi,a[i].num,a[i].mingci);
}
}
}
}
}
int main()
{
int n,g,i,j,k;
FILE *fw;
fw=fopen("D:\\hujian.txt","w");
printf("*********** ****************** 1.shuru **************************************\n");
printf("*********** ****************** 2.chazhao **************************************\n");
printf("*********** ****************** 3.xianshi\cunchu **************************************\n");
printf("*********** ****************** 4.shanchu **************************************");
printf("\n qing xian shu ru bi sai xiang mu ge shu\n");
scanf("%d",&n);
printf("\nqing shu ru ni de xun ze(1-4)\n");
scanf("%d",&g);
while(g!=0)
{switch(g)
{
case 1:shuru();break;
case 2:chazhao();break;
case 3:cunchu(n);break;
case 4:shanchu(n);break;
default:printf("wrong\n");
}
printf("\nqing shu ru ni de xun ze(1.shuru 2.chazhao 3.cunchu\xianshi 4.shanchu 0==jiesu)\n");
scanf("%d",&g);}
return 0;
}
为什么那个cunchu函数显示不出来信息,,显示的全是0