| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 966 人关注过本帖
标题:这个程序,请问有什么问题
取消只看楼主 加入收藏
mooncakeduan
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-6-11
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
这个程序,请问有什么问题
这个程序添加了歌曲,但是显示不出来,而且还删除不了。。



#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#define max 20
 int sum;
typedef struct
{
    int  num;
    char name[20];
    char kind[20];
    char singer[20];
    char save_time[20];
   
}SONG;





/*歌曲信息*/
int read_file(SONG songs[])
{
  FILE *fp;
  int i;
  if((fp=fopen("D:\\songsguanli.txt","rb"))==NULL)
   {
     printf("\n\n*****库存文件不存在!请创建");
     return(0);
   }
   else for(i=0;i<max;i++)
    songs[i].num=0;
   i=0;
   while(!feof(fp))
   {
     fread(&songs[i],sizeof(SONG),1,fp);
       if(songs[i].num==0)
              break;              
       else
         i++;
   }
   fclose(fp);
   return(i);
}                 




void save_file(SONG songs[], int sum)
{
 FILE *fp;
 int i;
 if((fp=fopen("D:\\songsguanli.txt","wb"))==NULL)
   {
     printf("读文件错误!!\n");
  getch();
     return;
   }
 for(i=0;i<sum;i++)
  {
    if(fwrite(&songs[i],sizeof(SONG),1,fp)==1)
    printf("写文件错误!\n\n");
  }

 fclose(fp);
}





/*输入模块 */
int input(SONG songs[])
{
  int i=0,choice;
  system("cls");
  printf("\n\n                      录入歌曲信息  (最多%d种)\n",max);
  printf("                ..........................................\n");
  do
  {
     printf("\n     (请歌曲号与其统一)   第%d首歌",i+1);
     printf("\n                      歌曲号:");
     scanf("%d",&songs[i].num);
  if(songs[i].num==0) break;
     printf("\n                      歌曲名称:");
     scanf("%s",&songs[i].name);
     printf("\n                      歌曲类型:");
     scanf("%s",&songs[i].kind);
     printf("\n                      歌手名字:");
     scanf("%s",&songs[i].singer);
     printf("\n                      存储时间:");
     scanf("%s",&songs[i].save_time);
     i++;
     printf(" \n           是否继续输入信息?(Y/others)");
     choice=getch();
     if(choice!='Y'&&choice!='y')
  {  
   break;
  }
     
  }while(i<max);
  return (i) ;
}






int apend(SONG songs[],int sum)
{
 int choice;
 system("cls");
 
    do
 {
     printf("      第%d首歌曲",sum+1);
     printf("\n                      歌曲号:");
     scanf("%d",&songs[sum+1].num);
     printf("\n                      歌曲名称:");
     scanf("%s",&songs[sum+1].name);
     printf("\n                      歌曲类型:");
     scanf("%s",&songs[sum+1].kind);
     printf("\n                      歌手名字:");
     scanf("%s",&songs[sum+1].singer);
     printf("\n                      存储时间:");

     scanf("%s",&songs[sum+1].save_time);
     sum++;
     printf(" \n           是否继续输入信息?(Y/others)");
     choice=getch();
     if(choice!='Y'||choice!='y')  
  {
   break;
  }
  
     
 }while(sum+1<max);
 return (sum);
}






void output(SONG songs[],int sum)
{
    int i=0;
    system("cls");
    printf("\n\n                 .....歌曲信息表......\n");
    printf("歌曲号--歌曲名称--歌曲类型--歌手名字--存储日期(年-月-日)\n");
    printf(".........................................................\n");
    for(i=0;i<sum;i++)
    {
        printf("%4d %8s %8s %8s %8s\n",songs[i].num,songs[i].name,songs[i].kind,songs[i].singer,songs[i].save_time);
      
    }
    printf("                    按任意键返回主菜单!");
    getch();

}





int modify(SONG songs[],int sum)
{
    int i=0,modify_num,flag;
    char choice;
    do
    {
        system("cls");
        printf("\n               请输入要修改的歌曲号:");
        scanf("%d",&modify_num);
        for (i=0;i<sum;i++)
        {
            if(songs[i].num==modify_num)
            {
               printf("\n              --歌曲信息--\n");
               printf("歌曲号--歌曲名称--歌曲类型--歌手名字--存储日期(年-月-日)");
               printf("........................................................................................................");
               printf("%4d %8s %8s %8s %8s\n",songs[i].num,songs[i].name,songs[i].kind,songs[i].singer,songs[i].save_time);
               printf("\n               你要修改哪一项?\n");
               printf("\n               1.歌曲名称\n");
               printf("\n               2.歌曲类型 \n");
               printf("\n               3.歌手名字\n");
               printf("\n               4.存储时间\n");
               scanf("%d",&choice);
               switch(choice)
               {

                   case 1:   printf("\n         请输入修改后的歌曲名称:");
                             scanf("%s",&songs[i].name);
        break;
                   case 2:   printf("\n         请输入修改后的歌曲类型:");
                             scanf("%s",&songs[i].kind);
        break;
                   case 3:   printf("\n         请输入修改后的歌手名字:");
                             scanf("%s",&songs[i].singer);
        break;
                   case 4:   printf("\n          请输入修改后的时间:");
        scanf("%s",&songs[i].save_time);
        break;
                                 
               }
               printf("\n              --歌曲信息--\n");
               printf("歌曲号--歌曲名称--歌曲类型--歌手名字--存储日期(年-月-日)\n");
               printf(".........................................................\n");
               printf("%4d %8s %8s %8s %8s\n",songs[i].num,songs[i].name,songs[i].kind,
               songs[i].singer,songs[i].save_time);
            
            }
            break;
        }
        if (i==sum)
        {
            printf("\n       不存在该歌曲!!!!" );
   getch();
            return 0;
        }
        printf("\n\n              继续修改吗?(Y/others)");
        choice=getch();
        if(choice=='Y'||choice=='y')
        {
        flag=1;
        }
        else flag=0;
    }while(flag==1);
    printf("   按任意键返回主菜单!!  ");
    getch();
    return 0;
   
}





/*删除模块*/
int del(SONG songs[],int sum)
{
  int j,i,flag=0 ;
  char s[20];
  system("cls");
  printf("   请输入要删除的歌曲名字:\n");

  scanf("%s",s);
  for(i=0;i<sum;i++)
  {   
   if(strcmp(songs[i].name,s)==0)
   {
         flag=1;
   for(j=i;j<sum-1;j++)
   {
            songs[j]=songs[j+1];
   }
   }
   if(flag==0)
   {
    printf("不存在该歌曲!!!\n");
   }
   if(flag==1)
   {
    printf("删除成功!!");
    getch();
   }
   sum--;
  }
  return sum;


}
/*chazhao */
void cha(SONG songs[],int sum)
{
 char  cha_name[20];
 int i=1;
 system("cls");
 printf("请输入要查找的歌曲名\n");
 scanf("%s",&cha_name);
 do
 {
  if (songs[i].name==cha_name)
  {
             printf("\n              --歌曲信息--\n");
             printf("歌曲号--歌曲名称--歌曲类型--歌手名字--存储日期(年-月-日)");
             printf("........................................................................................................");
             printf("%4d %8s %8s %8s %8s\n",songs[i].num,songs[i].name,songs[i].kind,
             songs[i].singer,songs[i].save_time);
      
  }
  i++;
 }while(i<=sum);
 printf("按任意键返回主菜单!!!");
 getch();
 return;
}
void main()
{
    SONG songs[max];
    int choice;
   sum=read_file(songs);
    if(sum==0)
    {
        printf("请录入基本库存信息!!!");
        getch();
        sum=input(songs);
  save_file(songs,sum);
    }
    do
    {

        system("cls");
        printf("\n\n\n           *****歌曲管理*****\n\n");
        printf("                1.添加歌曲          **\n\n");
  printf("                2.查看歌曲          **\n\n");
        printf("                3.删除歌曲          **\n\n");
        printf("                4.修改歌曲          **\n\n");
        printf("                5.查找歌曲          **\n\n");
        printf("                0.退出系统          **\n\n");
        scanf("%d",&choice);
        switch(choice)
        {
            case 1: apend(songs,sum);             break;
            case 2: output(songs,sum);            break;
            case 3: del(songs,sum) ;              break;
            case 4: modify( songs, sum) ;         break;
            case 5: cha(songs,sum);               break;
            case 0:                               break;

  }
 }while(choice!=0);
        
 save_file(songs,sum);
}

搜索更多相关主题的帖子: 而且 include return singer 
2010-06-11 21:38
mooncakeduan
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-6-11
收藏
得分:0 
没人我自己顶1~
2010-06-11 21:41
mooncakeduan
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-6-11
收藏
得分:0 
我再顶!~
2010-06-12 20:07
快速回复:这个程序,请问有什么问题
数据加载中...
 
   



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

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