该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
/*************************************************查询函数**********************************************/
void search()
{
int flag,j,x;
char w[20];
FILE *fp;
char v[20];
printf("(1)按作者\n");
printf("(2)按歌手\n");
printf("(3)按曲名\n");
printf("请选择操作方式:\n");
scanf("%d",&x);
if(x==3)
{
flag=0;
printf("请输入歌曲名称:");
scanf("%s",&w);
fp=fopen("data.txt","rb");
for(j=0;j<100;j++)
{
if(fread(&dan[j],sizeof(struct song),1,fp)!=1) break;
if(strcmp(dan[j].name,w)==0)
{
printf("曲名:%s\n",dan[j].name);
printf("作者:%s\n",dan[j].author);
printf("歌手:%s\n",dan[j].singer);
printf("发行日期:%s\n",dan[j].time);
printf("---------------------------------\n");
flag=1;
}
}
if(flag==0)
printf("未找到歌曲!\n");
fclose(fp);
}
else if(x==2)
{
flag=0;
printf("请输入歌手:");
scanf("%s",&v);
fp=fopen("data.txt","rb");
for(j=0;j<100;j++)
{
if(fread(&dan[j],sizeof(struct song),1,fp)!=1) break;
if(strcmp(dan[j].singer,v)==0)
{
printf("曲名:%s\n",dan[j].name);
printf("作者:%s\n",dan[j].author);
printf("歌手:%s\n",dan[j].singer);
printf("发行日期:%s\n",dan[j].time);
printf("---------------------------------\n");
flag=1;
}
}
if(flag==0)
printf("未找到歌曲!\n");
fclose(fp);
}
else if(x==1)
{
flag=0;
printf("请输入作者:");
scanf("%s",w);
fp=fopen("data.txt","rb");
for(j=0;j<100;j++)
{
if(fread(&dan[j],sizeof(struct song),1,fp)!=1) break;
if(strcmp(dan[j].author,w)==0)
{
printf("曲名:%s\n",dan[j].name);
printf("作者:%s\n",dan[j].author);
printf("歌手:%s\n",dan[j].singer);
printf("发行日期:%s\n",dan[j].time);
printf("---------------------------------\n");
flag=1;
}
}
if(flag==0)
printf("未找到歌曲!\n");
fclose(fp);
}
else printf("Error!\n");
}
/*******************************************************************************************************/
/**************************************************主函数**********************************************/
void main()
{
int a;
while(1)
{
printf("/**********************************歌曲信息管理系统****************************/");
printf("\t\t\t\t1.歌曲输入\n");
printf("\t\t\t\t2.歌曲删除\n");
printf("\t\t\t\t3.歌曲浏览\n");
printf("\t\t\t\t4.歌曲查询\n");
printf("\t\t\t\t0.退出\n");
printf("/*****************************************************************************/\n");
printf("请选择操作种类(0-4):");
scanf("%d",&a);
if(a==0) break;
switch(a)
{
case 1:enter();break;
case 2:delete1();break;
case 3:browse();break;
case 4:search();break;
}
}
}
/*************************************************end 赖德发.2014.01.04****************************************************/