|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
大佬们帮忙看下,模拟KTV点歌系统,为啥编译运行后会报这
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct musics{
char singer[1000];
char songs[100][1000];
int song_num;
};
struct musics mus[1000];
void admin(){
//登陆的逻辑
char input_user[100];
char input_passwd[100];
char user[100];
char passwd[100];
FILE *fp1;
fp1 = fopen("C:\\Users\\lenovo\\Documents\\Tencent Files\\522249165\\chengxu\\admin.txt","r");
while(!feof(fp1)){
fscanf(fp1,"%s",user);
fscanf(fp1,"%s",passwd);
}
printf("-------请输入用户名-------\n");
scanf("%s",input_user);
printf("-------请输入密码-------\n");
scanf("%s",input_passwd);
if(strcmp(input_user,user)==0){
if(strcmp(input_passwd,passwd)==0){
printf("-------登陆成功-------\n");
}else{
printf("-------密码不正确-------");
return;
}
}else{
printf("-------用户名不正确-------");
return;
}
fclose(fp1);
//添加和删除的逻辑
int option;
while(1){
char buffer[1000];
char name[1000];
char singertemp[1000];
char singer[1000]="*";
FILE *fp2;
FILE *fp3;
fp2 = fopen("C:\\Users\\lenovo\\Documents\\Tencent Files\\522249165\\chengxu\\a.txt","r+");
fp3 = fopen("C:\\Users\\lenovo\\Documents\\Tencent Files\\522249165\\chengxu\\temp.txt","a");
printf("-------请输入要进行的操作:1.添加 歌曲 2.删除歌曲 其他任意键退出-------\n");
scanf("%d",&option);
if(option==1){
printf("-------请输入你要添加的歌手-------\n");
scanf("%s",&singertemp);
printf("-------请输入你要添加的歌曲-------\n");
scanf("%s",&name);
strcat(singer,singertemp);
while(!feof(fp2)){
fscanf(fp2,"%s",buffer);
if(strcmp(singer,buffer)==0){
fprintf(fp3," %s ",buffer);
fprintf(fp3," %s ",name);
}else{
fprintf(fp3," %s ",buffer);
}
}
fprintf(fp3," %s ",singer);
fprintf(fp3," %s ",name);
fclose(fp2);
fclose(fp3);
rename("C:\\Users\\lenovo\\Documents\\Tencent Files\\522249165\\chengxu\\temp.txt","C:\\Users\\lenovo\\Documents\\Tencent Files\\522249165\\chengxu\\a.txt");
}else if(option==2){
printf("-------请输入你要删除的歌曲-------\n");
scanf("%s",&name);
strcat(name,".mp3");
while(!feof(fp2)){
fscanf(fp2,"%s",buffer);
if(strcmp(buffer,name)!=0){
fprintf(fp3,"%s ",buffer);
printf("%s\n",buffer);
}
}
fclose(fp3);
fclose(fp2);
rename("C:\\Users\\lenovo\\Documents\\Tencent Files\\522249165\\chengxu\\temp.txt","C:\\Users\\lenovo\\Documents\\Tencent Files\\522249165\\chengxu\\a.txt");
}else{
return;
}
}
}
void play_mus(int i, int j){
char buffer[1000];
char filename[1024]="C:\\Users\\lenovo\\Documents\\Tencent Files\\522249165\\chengxu\\";
char *token = strtok(mus[i].songs[j],".");
strcat(filename,token);
strcat(filename,".txt");
FILE *fp;
fp = fopen(filename,"r");
while(!feof(fp)){
fgets(buffer,500,fp);
printf("%s\n",buffer);
}
fclose(fp);
printf("-------播放结束-------\n");
}
//初始化歌曲的函数
int init(){
char buffer[500];
FILE *fp;
int singer_num=-1;
int index=0;
fp = fopen("C:\\Users\\lenovo\\Documents\\Tencent Files\\522249165\\chengxu\\a.txt","r");
while(!feof(fp)){
fscanf(fp,"%s",buffer);
if(strchr(buffer,'*')){
index=0;
singer_num++;
mus[singer_num].song_num = 0;
strcpy(mus[singer_num].singer,buffer+1);
}else{
strcpy(mus[singer_num].songs[index],buffer);
mus[singer_num].song_num++;
index++;
}
}
fclose(fp);
return singer_num;
}
//查找歌曲的函数
int search(int singer_num){
int choice;
int find=0;
char name[1024];
printf("-------请选择何种查询方式:1.根据歌手名查找 2.根据歌名查找 其他.返回上一级-------\n");
scanf("%d",&choice);
if(choice==1){
int i1,j1;
printf("-------请输入歌手名-------\n");
scanf("%s",&name);
for(int i=0;i<=singer_num;i++){
if(strcmp(mus[i].singer,name)==0){
find=1;
for(int j=0;j<mus[i].song_num;j++){
printf("%d.%s\n",j,mus[i].songs[j]);
i1=i;
}
}
}
if(find==0){
printf("-------没有发现这个歌手-------\n");
}else{
printf("-------请输入歌曲前面的序号,退出请输入-1-------\n");
scanf("%d",&j1);
if(j1=='*'){
return 1;
}else{
play_mus(i1, j1);
}
}
}else if(choice==2){
int i1,j1;
printf("-------请输入歌曲名-------\n");
scanf("%s",&name);
strcat(name,".mp3");
for(int i=0;i<=singer_num;i++){
for(int j=0;j<mus[i].song_num;j++){
if(strcmp(mus[i].songs[j],name)==0){
find=1;
printf("%d.%s\n",j,mus[i].songs[j]);
i1=i;
}
}
}
if(find==0){
printf("-------没有发现这个歌手-------\n");
}else{
printf("-------请输入歌曲前面的序号,退出请输入-1-------\n");
scanf("%d",&j1);
if(j1=='-1'){
return 1;
}else{
play_mus(i1, j1);
}
}
}else{
return -1;
}
return 0;
}
int main(){
int option;
while(1){
int num = init();
printf("-------请输入要进行的操作: 1.查找歌曲 2.管理员模式 按任意键退出---------\n");
scanf("%d",&option);
switch(option){
case 1: search(num);break;
case 2: admin();break;
default: return 1;
}
}
}
|
-
|