初始提交:添加三个游戏(进制转换、背单词、点歌台管理)
This commit is contained in:
commit
6e62e4477b
60
.gitignore
vendored
Normal file
60
.gitignore
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
# ---> C
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
13
CMakeLists.txt
Normal file
13
CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.30)
|
||||
project(simple C)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
|
||||
add_executable(simple main.c conversion/C1main.c
|
||||
word/C2main.c
|
||||
muisc_message/C3main.c
|
||||
muisc_message/User/C3_User.c
|
||||
muisc_message/Admin/C3_Admin.c
|
||||
muisc_message/Shear/C3_shear.c)
|
||||
|
BIN
conversion/ASCII码.png
Normal file
BIN
conversion/ASCII码.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 125 KiB |
193
conversion/C1main.c
Normal file
193
conversion/C1main.c
Normal file
@ -0,0 +1,193 @@
|
||||
//
|
||||
// Created by CC-star on 25-5-6.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int R,num;//需要得到的进制,输入的整数
|
||||
char num_16[100]; // 十六进制
|
||||
int R_choice;//原本进制
|
||||
|
||||
|
||||
// void Pr_Start() {
|
||||
// int power = 1; // R进制的幂,从R^0=1开始
|
||||
// }
|
||||
|
||||
|
||||
//十进制转2进制
|
||||
void DectoBin() {
|
||||
int arr[100],length = 0;
|
||||
while(num){
|
||||
arr[length++] = num % 2;
|
||||
num/=2;
|
||||
}
|
||||
printf("对应2进制表示为:");
|
||||
for(int i = length-1;i>=0;i--){
|
||||
printf("%d",arr[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
//十进制转R进制
|
||||
void DectoR() {
|
||||
switch(R){
|
||||
//十进制转二进制
|
||||
case 2:
|
||||
DectoBin();
|
||||
break;
|
||||
//十进制转8进制
|
||||
case 8:
|
||||
printf("对应8进制表示为:%o\n",num);
|
||||
break;
|
||||
case 10:
|
||||
printf("对应10进制表示为:%d\n",num);
|
||||
break;
|
||||
//十进制转16进制
|
||||
case 16:
|
||||
printf("对应16进制表示为:%x\n",num);
|
||||
break;
|
||||
default:
|
||||
printf("输入有误!目前只支持2、8、10、16进制间的转换\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//2进制转10进制
|
||||
void BintoDec() {
|
||||
int s = 0;
|
||||
int i = 0;
|
||||
int power = 1;
|
||||
while (num > 0) {
|
||||
s += (num % 10) * power;
|
||||
power *= 2;
|
||||
num/=10;
|
||||
i++;
|
||||
}
|
||||
num = s;
|
||||
DectoR();
|
||||
}
|
||||
|
||||
//8进制转10进制
|
||||
void OcttoDec() {
|
||||
int s = 0;
|
||||
int i = 0;
|
||||
int power = 1;
|
||||
while (num > 0) {
|
||||
s += (num % 10) * power;
|
||||
power *= 8;
|
||||
num/=10;
|
||||
i++;
|
||||
}
|
||||
num = s;
|
||||
DectoR();
|
||||
}
|
||||
|
||||
//16进制转10进制
|
||||
void HextoDec() {
|
||||
int s = 0; // 十进制结果
|
||||
int len = strlen(num_16);
|
||||
int power = 1;
|
||||
for(int i = len-1; i >= 0; i--) {
|
||||
int digit;
|
||||
|
||||
if(num_16[i] >= '0' && num_16[i] <= '9') {
|
||||
digit = num_16[i] - '0';
|
||||
}
|
||||
else if(num_16[i] >= 'A' && num_16[i] <= 'F') {
|
||||
digit = num_16[i] - 'A' + 10;
|
||||
}
|
||||
else if(num_16[i] >= 'a' && num_16[i] <= 'f') {
|
||||
digit = num_16[i] - 'a' + 10;
|
||||
}
|
||||
else {
|
||||
// 既不是数字也不是字母a-f/A-F,输入错误
|
||||
printf("错误:输入的不是有效的%d进制数!\n",R_choice);
|
||||
return ;
|
||||
}
|
||||
s = s + digit * power;
|
||||
power *= 16;
|
||||
}
|
||||
num = s;
|
||||
DectoR();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Input() {
|
||||
printf("输入你的%d进制数:",R_choice);
|
||||
scanf("%d",&num);
|
||||
while (getchar() != '\n');
|
||||
if(num < 0) {
|
||||
printf("错误:请输入正数!\n");
|
||||
return 0;
|
||||
}
|
||||
int tmp = num;
|
||||
int a;
|
||||
while (tmp > 0) {
|
||||
a = tmp % 10;
|
||||
if (a >= R_choice) {
|
||||
printf("错误:输入的不是有效的%d进制数!\n",R_choice);
|
||||
return 0;
|
||||
}
|
||||
tmp /= 10;//去掉个位
|
||||
}
|
||||
printf("输入你要得到的R进制:");
|
||||
scanf("%d",&R);
|
||||
while (getchar() != '\n');
|
||||
return 1;
|
||||
}
|
||||
|
||||
int C1main(){
|
||||
int opt;
|
||||
while (1) {
|
||||
printf("---------------------👇进制转换【整数|正数】控制面板👇----------------------\n");
|
||||
printf("1:2进制转R\n2:8进制转R\n");
|
||||
printf("3:10进制转R\n4:16进制转R\n");
|
||||
printf("0.返回主控制台\n");
|
||||
printf("-----------------------👆选择对应数字👆------------------------\n");
|
||||
printf("请输入选择:");
|
||||
scanf("%d", &opt);
|
||||
//固定原始数字的进制
|
||||
if (opt == 1) {
|
||||
R_choice =2;
|
||||
}else if(opt == 2) {
|
||||
R_choice=8;
|
||||
}else if(opt == 3) {
|
||||
R_choice=10;
|
||||
}else if(opt == 4) {
|
||||
R_choice=16;
|
||||
}
|
||||
switch (opt) {
|
||||
case 1://2进制转R
|
||||
if(Input() == 1) {
|
||||
BintoDec();
|
||||
}
|
||||
break;
|
||||
case 2://8进制转R
|
||||
if(Input() == 1) {
|
||||
OcttoDec();
|
||||
}
|
||||
break;
|
||||
case 3://10进制转R
|
||||
if(Input() == 1) {
|
||||
DectoR();
|
||||
}
|
||||
break;
|
||||
case 4://16进制转R
|
||||
printf("输入你的16进制数:");
|
||||
scanf("%s", num_16);
|
||||
printf("输入你要得到的R进制:");
|
||||
scanf("%d",&R);
|
||||
HextoDec();
|
||||
break;
|
||||
case 0:
|
||||
printf("⚠️返回主控制台中...⚠️\n");
|
||||
return 0;
|
||||
default:
|
||||
printf("⚠️输入有误,请重新输入⚠️\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
38
main.c
Normal file
38
main.c
Normal file
@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int C1main();
|
||||
int C2main();
|
||||
int C3main();
|
||||
|
||||
int main(void) {
|
||||
while (1) {
|
||||
printf("\n---------------------👇题目面板👇----------------------\n");
|
||||
printf("1.进制转换\n");
|
||||
printf("2.背单词\n");
|
||||
printf("3.点歌台管理\n");
|
||||
printf("0.退出程序\n");
|
||||
printf("-----------------------👆选择对应数字👆------------------------\n");
|
||||
printf("请输入选择:");
|
||||
int opt;
|
||||
scanf("%d", &opt);
|
||||
while (getchar() != '\n');
|
||||
switch (opt) {
|
||||
case 1:
|
||||
printf("启动进制转换程序...\n");
|
||||
C1main();
|
||||
break;
|
||||
case 2:
|
||||
printf("启动背单词程序...\n");
|
||||
C2main();
|
||||
break;
|
||||
case 3:
|
||||
printf("启动点歌台管理程序...\n");
|
||||
C3main();
|
||||
break;
|
||||
case 0:
|
||||
return 0;
|
||||
default:
|
||||
printf("⚠️输入有误,请重新输入⚠️\n");
|
||||
}
|
||||
}
|
||||
}
|
468
muisc_message/Admin/C3_Admin.c
Normal file
468
muisc_message/Admin/C3_Admin.c
Normal file
@ -0,0 +1,468 @@
|
||||
//
|
||||
// Created by CC-star on 25-5-9.
|
||||
// (1) 管理员功能:
|
||||
//歌曲信息管理: 歌曲信息添加,查询,修改,删除,存盘,浏览等。
|
||||
//歌曲信息至少包括: 编号,歌手名,歌曲名,歌曲类别等。
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include "../Shear/C3_shear.h"
|
||||
|
||||
extern int songCount;
|
||||
|
||||
// 更新歌曲信息功能
|
||||
void Update_MusicInfo() {
|
||||
Read_MuiscFile();
|
||||
if (songCount > 0) {
|
||||
FILE *fp = fopen(MUSIC_PATH, "w");
|
||||
if (fp == NULL) {
|
||||
printf("无法打开文件进行写入:%s\n", MUSIC_PATH);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < songCount; i++) {
|
||||
// 编号-歌手名-歌曲名-歌曲类别
|
||||
fprintf(fp, "%d-%s-%s-%s\n",
|
||||
SongList[i].id,
|
||||
SongList[i].artist,
|
||||
SongList[i].name,
|
||||
SongList[i].category);
|
||||
}
|
||||
fclose(fp);
|
||||
printf("歌曲信息更新成功,写入%d首歌\n",songCount);
|
||||
} else {
|
||||
printf("未找到任何歌曲,不需要写入文件\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//歌曲修改
|
||||
void Alter_MusicInfo() {
|
||||
Read_MuiscFile();
|
||||
if (songCount > 0) {
|
||||
FILE *fp = fopen(MUSIC_PATH, "r");
|
||||
if (fp == NULL) {
|
||||
printf("无法打开文件进行写入:%s\n", MUSIC_PATH);
|
||||
return;
|
||||
}
|
||||
int opt,a,b;
|
||||
char c1[100],c2[100];
|
||||
while (1) {
|
||||
printf("\n---------------------👇歌曲信息修改依据👇----------------------\n");
|
||||
printf("1:id\n2.歌曲名\n3.歌手名\n4.歌曲类别\n");
|
||||
printf("0.返回控制台\n");
|
||||
printf("-----------------------👆选择对应数字👆------------------------\n");
|
||||
printf("请输入选择:");
|
||||
scanf("%d", &opt);
|
||||
while(getchar() != '\n');
|
||||
switch (opt) {
|
||||
case 1:
|
||||
printf("请输入需要修改的id(整数):");
|
||||
scanf("%d", &a);
|
||||
while(getchar() != '\n');
|
||||
// 先显示匹配的歌曲信息
|
||||
printf("\n---------------------👇匹配的歌曲信息👇----------------------\n");
|
||||
int found = 0;
|
||||
for (int i = 0; i < songCount; ++i) {
|
||||
if (a == SongList[i].id) {
|
||||
printf("%d-%s-%s-%s\n", SongList[i].id, SongList[i].artist, SongList[i].name, SongList[i].category);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
printf("未找到ID为%d的歌曲,无法进行修改操作\n", a);
|
||||
break;
|
||||
}
|
||||
printf("-----------------------👆歌曲信息👆------------------------\n");
|
||||
|
||||
printf("请输入修改后的id(整数):");
|
||||
scanf("%d", &b);
|
||||
while(getchar() != '\n');
|
||||
for (int i = 0; i < songCount; i++) {
|
||||
if (b == SongList[i].id) {
|
||||
printf("您输入的修改后的ID:%d,已存在,无法进行修改操作\n", b);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
printf("确认修改ID?(1.是,0.否):");
|
||||
int confirm;
|
||||
scanf("%d", &confirm);
|
||||
while(getchar() != '\n');
|
||||
if (!confirm) {
|
||||
printf("已取消修改操作\n");
|
||||
break;
|
||||
}
|
||||
//开始改
|
||||
for (int i = 0; i < songCount; ++i) {
|
||||
if (a == SongList[i].id) {
|
||||
char old_filename[256], new_filename[256];
|
||||
|
||||
sprintf(old_filename, "%s/%d-%s-%s-%s.mp3",
|
||||
MRES_PATH,
|
||||
SongList[i].id,
|
||||
SongList[i].artist,
|
||||
SongList[i].name,
|
||||
SongList[i].category);
|
||||
|
||||
SongList[i].id = b;
|
||||
|
||||
sprintf(new_filename, "%s/%d-%s-%s-%s.mp3",
|
||||
MRES_PATH,
|
||||
SongList[i].id,
|
||||
SongList[i].artist,
|
||||
SongList[i].name,
|
||||
SongList[i].category);
|
||||
|
||||
if (rename(old_filename, new_filename) == 0) {
|
||||
printf("歌曲 %s 的ID修改成功,文件已重命名\n", SongList[i].name);
|
||||
} else {
|
||||
printf("文件重命名失败,请检查文件是否存在\n");
|
||||
}
|
||||
fclose(fp);
|
||||
printf("歌曲信息自动更新中...\n");
|
||||
Update_MusicInfo();
|
||||
printf("修改完成,返回控制台\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
printf("请输入需要修改的歌曲名:");
|
||||
scanf("%[^\n]", c1);
|
||||
while(getchar() != '\n');
|
||||
printf("\n---------------------👇匹配的歌曲信息👇----------------------\n");
|
||||
found = 0;
|
||||
for (int i = 0; i < songCount; ++i) {
|
||||
if (strcmp(c1, SongList[i].name) == 0) {
|
||||
printf("%d-%s-%s-%s\n", SongList[i].id, SongList[i].artist, SongList[i].name, SongList[i].category);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
printf("未找到歌曲名为%s的歌曲,无法进行修改操作\n", c1);
|
||||
break;
|
||||
}
|
||||
printf("-----------------------👆歌曲信息👆------------------------\n");
|
||||
|
||||
|
||||
|
||||
printf("请输入修改后的歌曲名:");
|
||||
scanf("%[^\n]", c2);
|
||||
while(getchar() != '\n');
|
||||
for (int i = 0; i < songCount; i++) {
|
||||
if (strcmp(c2, SongList[i].name) == 0) {
|
||||
printf("您输入的修改后的歌曲名:%s,已存在,无法进行修改操作\n", c2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
printf("确认修改歌曲名?(1.是,0.否):");
|
||||
scanf("%d", &confirm);
|
||||
while(getchar() != '\n');
|
||||
if (!confirm) {
|
||||
printf("已取消修改操作\n");
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < songCount; ++i) {
|
||||
if (strcmp(c1, SongList[i].name) == 0) {
|
||||
char old_filename[256], new_filename[256];
|
||||
|
||||
sprintf(old_filename, "%s/%d-%s-%s-%s.mp3",
|
||||
MRES_PATH,
|
||||
SongList[i].id,
|
||||
SongList[i].artist,
|
||||
SongList[i].name,
|
||||
SongList[i].category);
|
||||
|
||||
strcpy(SongList[i].name, c2);
|
||||
|
||||
sprintf(new_filename, "%s/%d-%s-%s-%s.mp3",
|
||||
MRES_PATH,
|
||||
SongList[i].id,
|
||||
SongList[i].artist,
|
||||
SongList[i].name,
|
||||
SongList[i].category);
|
||||
|
||||
if (rename(old_filename, new_filename) == 0) {
|
||||
printf("歌曲名修改成功,文件已重命名\n");
|
||||
} else {
|
||||
printf("文件重命名失败,请检查文件是否存在\n");
|
||||
}
|
||||
fclose(fp);
|
||||
printf("歌曲信息自动更新中...\n");
|
||||
Update_MusicInfo();
|
||||
printf("修改完成,返回控制台\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
printf("请输入需要修改的歌手名:");
|
||||
scanf("%[^\n]", c1);
|
||||
while(getchar() != '\n');
|
||||
|
||||
printf("\n---------------------👇匹配的歌曲信息👇----------------------\n");
|
||||
found = 0;
|
||||
for (int i = 0; i < songCount; ++i) {
|
||||
if (strcmp(c1, SongList[i].artist) == 0) {
|
||||
printf("%d-%s-%s-%s\n", SongList[i].id, SongList[i].artist, SongList[i].name, SongList[i].category);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
printf("未找到匹配的歌手名,无法进行修改操作\n");
|
||||
break;
|
||||
}
|
||||
printf("-----------------------👆歌曲信息👆------------------------\n");
|
||||
|
||||
|
||||
|
||||
printf("请输入修改后的歌手名:");
|
||||
scanf("%[^\n]", c2);
|
||||
while(getchar() != '\n');
|
||||
|
||||
printf("确认修改所有匹配歌曲的歌手名?(1.是,0.否):");
|
||||
scanf("%d", &confirm);
|
||||
while(getchar() != '\n');
|
||||
if (!confirm) {
|
||||
printf("已取消修改操作\n");
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < songCount; ++i) {
|
||||
if (strcmp(c1, SongList[i].artist) == 0) {
|
||||
char old_filename[256], new_filename[256];
|
||||
|
||||
sprintf(old_filename, "%s/%d-%s-%s-%s.mp3",
|
||||
MRES_PATH,
|
||||
SongList[i].id,
|
||||
SongList[i].artist,
|
||||
SongList[i].name,
|
||||
SongList[i].category);
|
||||
|
||||
strcpy(SongList[i].artist, c2);
|
||||
|
||||
|
||||
sprintf(new_filename, "%s/%d-%s-%s-%s.mp3",
|
||||
MRES_PATH,
|
||||
SongList[i].id,
|
||||
SongList[i].artist,
|
||||
SongList[i].name,
|
||||
SongList[i].category);
|
||||
|
||||
if (rename(old_filename, new_filename) == 0) {
|
||||
printf("歌曲 %s 的歌手名修改成功,文件已重命名\n", SongList[i].name);
|
||||
} else {
|
||||
printf("歌曲 %s 的文件重命名失败,请检查文件是否存在\n", SongList[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
printf("歌曲信息自动更新中...\n");
|
||||
Update_MusicInfo();
|
||||
printf("修改完成,返回控制台\n");
|
||||
return;
|
||||
|
||||
case 4:
|
||||
printf("请输入需要修改的歌曲类别:");
|
||||
scanf("%[^\n]", c1);
|
||||
while(getchar() != '\n');
|
||||
printf("\n---------------------👇匹配的歌曲信息👇----------------------\n");
|
||||
found = 0;
|
||||
for (int i = 0; i < songCount; ++i) {
|
||||
if (strcmp(c1, SongList[i].category) == 0) {
|
||||
printf("%d-%s-%s-%s\n", SongList[i].id, SongList[i].artist, SongList[i].name, SongList[i].category);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
printf("未找到匹配的歌曲类别,无法进行修改操作\n");
|
||||
break;
|
||||
}
|
||||
printf("-----------------------👆歌曲信息👆------------------------\n");
|
||||
|
||||
|
||||
printf("请输入修改后的歌曲类别:");
|
||||
scanf("%[^\n]", c2);
|
||||
while(getchar() != '\n');
|
||||
|
||||
|
||||
printf("确认修改所有匹配歌曲的类别?(1.是,0.否):");
|
||||
scanf("%d", &confirm);
|
||||
while(getchar() != '\n');
|
||||
if (!confirm) {
|
||||
printf("已取消修改操作\n");
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < songCount; ++i) {
|
||||
if (strcmp(c1, SongList[i].category) == 0) {
|
||||
char old_filename[256], new_filename[256];
|
||||
|
||||
|
||||
sprintf(old_filename, "%s/%d-%s-%s-%s.mp3",
|
||||
MRES_PATH,
|
||||
SongList[i].id,
|
||||
SongList[i].artist,
|
||||
SongList[i].name,
|
||||
SongList[i].category);
|
||||
|
||||
strcpy(SongList[i].category, c2);
|
||||
|
||||
|
||||
sprintf(new_filename, "%s/%d-%s-%s-%s.mp3",
|
||||
MRES_PATH,
|
||||
SongList[i].id,
|
||||
SongList[i].artist,
|
||||
SongList[i].name,
|
||||
SongList[i].category);
|
||||
|
||||
if (rename(old_filename, new_filename) == 0) {
|
||||
printf("歌曲 %s 的类别修改成功,文件已重命名\n", SongList[i].name);
|
||||
} else {
|
||||
printf("歌曲 %s 的文件重命名失败,请检查文件是否存在\n", SongList[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
printf("歌曲信息自动更新中...\n");
|
||||
Update_MusicInfo();
|
||||
printf("修改完成,返回控制台\n");
|
||||
return;
|
||||
case 0:
|
||||
printf("⚠️返回控制台中...⚠️\n");
|
||||
return;
|
||||
default:
|
||||
printf("⚠️输入有误,请重新输入⚠️\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
printf("未找到任何歌曲,无法修改文件\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//删除歌曲
|
||||
void Delete_MusicInfo() {
|
||||
Read_MuiscFile();
|
||||
if (songCount <= 0) {
|
||||
printf("曲库为空,无法执行删除操作\n");
|
||||
return;
|
||||
}
|
||||
|
||||
FILE *fp = fopen(MUSIC_PATH, "r");
|
||||
if (fp == NULL) {
|
||||
printf("无法打开文件进行读取:%s\n", MUSIC_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
int a;
|
||||
printf("请输入需要删除的歌曲的id(整数):");
|
||||
scanf("%d", &a);
|
||||
while(getchar() != '\n');
|
||||
printf("\n---------------------👇匹配的歌曲信息👇----------------------\n");
|
||||
int found = 0;
|
||||
int index ; // 删除的歌曲的索引
|
||||
for (int i = 0; i < songCount; ++i) {
|
||||
if (a == SongList[i].id) {
|
||||
printf("%d-%s-%s-%s\n", SongList[i].id, SongList[i].artist, SongList[i].name, SongList[i].category);
|
||||
found = 1;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
printf("未找到ID为%d的歌曲,无法进行删除操作\n", a);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
printf("-----------------------👆歌曲信息👆------------------------\n");
|
||||
|
||||
printf("确认删除此歌曲?(1.是,0.否):");
|
||||
int confirm;
|
||||
scanf("%d", &confirm);
|
||||
while(getchar() != '\n');
|
||||
if (!confirm) {
|
||||
printf("已取消删除操作\n");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
char filename[256];
|
||||
sprintf(filename, "%s/%d-%s-%s-%s.mp3",
|
||||
MRES_PATH,
|
||||
SongList[index].id,
|
||||
SongList[index].artist,
|
||||
SongList[index].name,
|
||||
SongList[index].category);
|
||||
|
||||
if (remove(filename) == 0) {
|
||||
printf("歌曲文件删除成功: %s\n", filename);
|
||||
} else {
|
||||
printf("歌曲文件删除失败,请检查文件是否存在\n");
|
||||
}
|
||||
|
||||
for (int i = index; i < songCount - 1; i++) {
|
||||
SongList[i] = SongList[i + 1];
|
||||
}
|
||||
songCount--;
|
||||
|
||||
printf("歌曲 %s 已从曲库中删除\n", SongList[index].name);
|
||||
fclose(fp);
|
||||
|
||||
printf("歌曲信息自动更新中...\n");
|
||||
Update_MusicInfo();
|
||||
printf("删除操作完成,返回控制台\n");
|
||||
}
|
||||
|
||||
int C3_Admin() {
|
||||
char password[10];
|
||||
printf("请输入管理员密码: ");
|
||||
scanf("%s", password);
|
||||
if (strcmp(password,"1") == 0) {
|
||||
while (1) {
|
||||
printf("\n---------------------👇管理员控制面板👇----------------------\n");
|
||||
printf("1. 歌曲信息覆盖\n");
|
||||
printf("2. 歌曲查询\n");
|
||||
printf("3. 歌曲修改\n");
|
||||
printf("4. 歌曲删除\n");
|
||||
printf("5. 歌曲浏览\n");
|
||||
printf("0.返回控制台\n");
|
||||
printf("-----------------------👆选择对应数字👆------------------------\n");
|
||||
printf("请输入选择:");
|
||||
int opt;
|
||||
scanf("%d", &opt);
|
||||
while(getchar() != '\n');
|
||||
switch (opt) {
|
||||
case 1://歌曲信息更新
|
||||
Update_MusicInfo();
|
||||
break;
|
||||
case 2://歌曲查询
|
||||
Song_query();
|
||||
break;
|
||||
case 3://歌曲修改
|
||||
Alter_MusicInfo();
|
||||
break;
|
||||
case 4://歌曲删除
|
||||
Delete_MusicInfo();
|
||||
break;
|
||||
case 5://歌曲浏览
|
||||
BrowseSongs();
|
||||
break;
|
||||
case 0:
|
||||
printf("⚠️返回主控制台中...⚠️\n");
|
||||
return 0;
|
||||
default:
|
||||
printf("⚠️输入有误,请重新输入⚠️\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
65
muisc_message/C3main.c
Normal file
65
muisc_message/C3main.c
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// Created by CC-star on 25-5-9.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include "./Shear/C3_shear.h"
|
||||
|
||||
|
||||
int C3_User();
|
||||
int C3_Admin();
|
||||
void Update_MusicInfo();
|
||||
|
||||
//文件大小
|
||||
int File_information_size() {
|
||||
FILE *fp = fopen(MUSIC_PATH, "r");
|
||||
if (fp == NULL) {
|
||||
printf("无法打开歌曲列表文件!该程序无法正常使用,请先创建歌曲列表文件:music_list.txt\n");
|
||||
return 3;
|
||||
}
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
long fileSize= ftell(fp);
|
||||
// rewind(fp);
|
||||
fclose(fp);
|
||||
if (fileSize == 0) {
|
||||
printf("无歌曲信息,自动更新音乐歌单\n");
|
||||
return 2;
|
||||
}else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int C3main() {
|
||||
int ret = File_information_size();
|
||||
if (ret== 3) {
|
||||
return 0;
|
||||
} else if (ret == 2) {
|
||||
Update_MusicInfo();
|
||||
}
|
||||
|
||||
while (1) {
|
||||
printf("\n---------------------👇点歌台管理控制面板👇----------------------\n");
|
||||
printf("1:游客登入\n2:管理员登入\n");
|
||||
printf("0.返回主控制台\n");
|
||||
printf("-----------------------👆选择对应数字👆------------------------\n");
|
||||
printf("请输入选择:");
|
||||
int opt;
|
||||
scanf("%d", &opt);
|
||||
while (getchar() != '\n');
|
||||
switch (opt) {
|
||||
case 1:
|
||||
C3_User();
|
||||
break;
|
||||
case 2:
|
||||
C3_Admin();
|
||||
break;
|
||||
case 0:
|
||||
printf("⚠️返回主控制台中...⚠️\n");
|
||||
return 0;
|
||||
default:
|
||||
printf("⚠️输入有误,请重新输入⚠️\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
209
muisc_message/Shear/C3_shear.c
Normal file
209
muisc_message/Shear/C3_shear.c
Normal file
@ -0,0 +1,209 @@
|
||||
//
|
||||
// Created by CC-star on 25-5-9.
|
||||
//
|
||||
#include "C3_shear.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
extern int songCount;
|
||||
|
||||
//读取
|
||||
void Read_MuiscFile() {
|
||||
DIR *dir;//文件目录
|
||||
struct dirent *entry;//文件信息
|
||||
|
||||
dir = opendir(MRES_PATH);
|
||||
|
||||
if (dir == NULL) {
|
||||
printf("无法打开歌曲文件目录!\n");
|
||||
return;
|
||||
}
|
||||
songCount = 0;
|
||||
// 编号-歌手名-歌曲名-歌曲类别.mp3
|
||||
while ((entry = readdir(dir)) != NULL && songCount < 500) {
|
||||
char *filename = entry->d_name;
|
||||
|
||||
if (strstr(filename, ".mp3") != NULL) {
|
||||
char fileCopy[200];
|
||||
strcpy(fileCopy, filename);
|
||||
//id
|
||||
char *token = strtok(fileCopy, "-");
|
||||
if (token != NULL) {
|
||||
SongList[songCount].id = atoi(token);
|
||||
|
||||
// 歌手名
|
||||
token = strtok(NULL, "-");
|
||||
if (token != NULL) {
|
||||
strcpy(SongList[songCount].artist, token);
|
||||
|
||||
// 歌曲名
|
||||
token = strtok(NULL, "-");
|
||||
if (token != NULL) {
|
||||
strcpy(SongList[songCount].name, token);
|
||||
|
||||
// 歌曲类别
|
||||
token = strtok(NULL, ".");
|
||||
if (token != NULL) {
|
||||
strcpy(SongList[songCount].category, token);
|
||||
songCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
int i, j;
|
||||
struct Song temp;
|
||||
for (i = 0; i < songCount - 1; i++) {
|
||||
for (j = 0; j < songCount - i - 1; j++) {
|
||||
if (SongList[j].id > SongList[j + 1].id) {
|
||||
temp = SongList[j];
|
||||
SongList[j] = SongList[j + 1];
|
||||
SongList[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 歌曲浏览功能
|
||||
void BrowseSongs() {
|
||||
FILE *fp = fopen(MUSIC_PATH, "r");
|
||||
printf("\n---------------------👇歌曲列表👇----------------------\n");
|
||||
char line[500];
|
||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||
printf("%s", line);
|
||||
}
|
||||
printf("-----------------------👆歌曲列表👆------------------------\n");
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
//歌曲查询
|
||||
void Song_query() {
|
||||
int i = 0;//某一个歌曲信息
|
||||
FILE *fp = fopen(MUSIC_PATH, "r");
|
||||
if (fp == NULL) {
|
||||
printf("文件打开失败\n");
|
||||
return;
|
||||
}
|
||||
char line[100];
|
||||
// 编号-歌手名-歌曲名-歌曲类别
|
||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||
line[strcspn(line, "\n")] = 0;
|
||||
//ID
|
||||
char *token = strtok(line, "-");
|
||||
if (token != NULL) {
|
||||
SongList[i].id = atoi(token);
|
||||
//歌手
|
||||
token = strtok(NULL, "-");
|
||||
if (token != NULL) {
|
||||
strcpy(SongList[i].artist, token);
|
||||
//歌曲
|
||||
token = strtok(NULL, "-");
|
||||
if (token != NULL) {
|
||||
strcpy(SongList[i].name, token);
|
||||
|
||||
token = strtok(NULL, "-");
|
||||
if (token != NULL) {
|
||||
strcpy(SongList[i].category, token);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
int sum_song = i;
|
||||
while (1) {
|
||||
int found = 0;
|
||||
printf("\n---------------------👇歌曲查询信息类别👇----------------------\n");
|
||||
printf("1:id\n2.歌曲名\n3.歌手名\n4.歌曲类别\n");
|
||||
printf("0.返回控制台\n");
|
||||
printf("-----------------------👆选择对应数字👆------------------------\n");
|
||||
printf("请输入选择:");
|
||||
int opt,a;
|
||||
char c[100];
|
||||
scanf("%d", &opt);
|
||||
while(getchar() != '\n');
|
||||
switch (opt) {
|
||||
case 1:
|
||||
printf("请输入id:");
|
||||
scanf("%d", &a);
|
||||
while(getchar() != '\n');
|
||||
printf("\n---------------------👇您所查询的歌曲信息👇----------------------\n");
|
||||
for (int i = 0; i < sum_song; ++i) {
|
||||
if (a == SongList[i].id) {
|
||||
printf("%d-%s-%s-%s\n", SongList[i].id, SongList[i].artist, SongList[i].name, SongList[i].category);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (found == 0) {
|
||||
printf("⚠️未找到歌曲...⚠️\n");
|
||||
}
|
||||
printf("-----------------------👆歌曲信息👆------------------------\n");
|
||||
break;
|
||||
case 2:
|
||||
printf("请输入歌曲名:");
|
||||
scanf("%[^\n]", c);
|
||||
while(getchar() != '\n');
|
||||
printf("\n---------------------👇您所查询的歌曲信息👇----------------------\n");
|
||||
for (int i = 0; i < sum_song; ++i) {
|
||||
if (strcmp(c, SongList[i].name) == 0) {
|
||||
printf("%d-%s-%s-%s\n", SongList[i].id, SongList[i].artist, SongList[i].name, SongList[i].category);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (found == 0) {
|
||||
printf("⚠️未找到歌曲...⚠️\n");
|
||||
}
|
||||
printf("-----------------------👆歌曲信息👆------------------------\n");
|
||||
break;
|
||||
case 3:
|
||||
printf("请输入歌手名:");
|
||||
scanf("%[^\n]", c);
|
||||
while(getchar() != '\n');
|
||||
printf("\n---------------------👇您所查询的歌曲信息👇----------------------\n");
|
||||
for (int i = 0; i < sum_song; ++i) {
|
||||
if (strcmp(c, SongList[i].artist) == 0) {
|
||||
printf("%d-%s-%s-%s\n", SongList[i].id, SongList[i].artist, SongList[i].name, SongList[i].category);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (found == 0) {
|
||||
printf("⚠️未找到歌曲...⚠️\n");
|
||||
}
|
||||
printf("-----------------------👆歌曲信息👆------------------------\n");
|
||||
break;
|
||||
case 4:
|
||||
printf("请输入歌曲类别:");
|
||||
scanf("%s", c);
|
||||
while(getchar() != '\n');
|
||||
printf("\n---------------------👇您所查询的歌曲信息👇----------------------\n");
|
||||
for (int i = 0; i < sum_song; ++i) {
|
||||
if (strcmp(c, SongList[i].category) == 0) {
|
||||
printf("%d-%s-%s-%s\n", SongList[i].id, SongList[i].artist, SongList[i].name, SongList[i].category);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (found == 0) {
|
||||
printf("⚠️未找到歌曲...⚠️\n");
|
||||
}
|
||||
printf("-----------------------👆歌曲信息👆------------------------\n");
|
||||
break;
|
||||
case 0:
|
||||
printf("⚠️返回控制台中...⚠️\n");
|
||||
return;
|
||||
default:
|
||||
printf("⚠️输入有误,请重新输入⚠️\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
22
muisc_message/Shear/C3_shear.h
Normal file
22
muisc_message/Shear/C3_shear.h
Normal file
@ -0,0 +1,22 @@
|
||||
#define C3_SHEAR_H
|
||||
#define MUSIC_PATH "../muisc_message/Shear/music_list.txt"//歌单信息
|
||||
#define MRES_PATH "../muisc_message/mres"//歌曲文件夹
|
||||
|
||||
|
||||
struct Song{
|
||||
int id; // 编号
|
||||
char name[100]; // 歌曲名
|
||||
char artist[100]; // 歌手名
|
||||
char category[50]; // 歌曲类别
|
||||
} SongList[500];
|
||||
|
||||
|
||||
|
||||
int songCount; // 歌曲计数器,SongList中的歌曲数量
|
||||
|
||||
|
||||
void Read_MuiscFile();//读取
|
||||
void Song_query();//查询
|
||||
void BrowseSongs();//游览
|
||||
|
||||
|
8
muisc_message/Shear/music_list.txt
Normal file
8
muisc_message/Shear/music_list.txt
Normal file
@ -0,0 +1,8 @@
|
||||
1-Justin Bieber-sorry-英文
|
||||
2-方大同-听-中文
|
||||
3-林俊杰-江南-中文
|
||||
5-方大同-听2-中文
|
||||
6-方大同-听3-中文
|
||||
7-Justin Bieber-Die for you-英文
|
||||
8-Justin Bieber-Die for you2-英文
|
||||
9-Justin Bieber-sorry3-英文
|
268
muisc_message/User/C3_User.c
Normal file
268
muisc_message/User/C3_User.c
Normal file
@ -0,0 +1,268 @@
|
||||
//
|
||||
// Created by CC-star on 25-5-9.
|
||||
//
|
||||
|
||||
// (2) 用户功能:
|
||||
// 多种类型的歌曲查询、显示功能:
|
||||
// 按歌曲名、歌手名、歌曲类别等查询歌曲。
|
||||
// 点歌功能:用户录入歌曲编号,被点播歌曲按点播顺序放入播放表,每一分钟删除最前面一首歌,表示已经播放完毕。
|
||||
// 当全部点播歌曲播放完毕,提示"点播歌曲已经播完,请继续点播"。
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "../Shear/C3_shear.h"
|
||||
// 播放队列
|
||||
typedef struct {
|
||||
int songIds[100]; // 歌曲ID
|
||||
int count; // 歌曲数量
|
||||
} PlayQueue;
|
||||
|
||||
// PlayQueue playQueue = {.count = 0}; // 指定count = 0
|
||||
PlayQueue playQueue = {0};
|
||||
// int i;//找到的歌曲索引
|
||||
|
||||
|
||||
// 显示当前播放队列
|
||||
void ShowPlayQueue() {
|
||||
printf("\n---------------------👇当前播放队列👇----------------------\n");
|
||||
if (playQueue.count == 0) {
|
||||
printf("播放队列为空\n");
|
||||
} else {
|
||||
for (int i = 0; i < playQueue.count; i++) {
|
||||
for (int j = 0; j < songCount; j++) {
|
||||
if (SongList[j].id == playQueue.songIds[i]) {
|
||||
printf("%d. %s - %s\n", i + 1, SongList[j].artist, SongList[j].name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("-----------------------👆播放队列👆------------------------\n");
|
||||
}
|
||||
|
||||
// 移除队列中的第一首歌
|
||||
void RemoveFirstSong() {
|
||||
if (playQueue.count > 0) {
|
||||
for (int i = 0; i < playQueue.count - 1; i++) {
|
||||
playQueue.songIds[i] = playQueue.songIds[i + 1];
|
||||
}
|
||||
playQueue.count--;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayMusic(int songId) {
|
||||
char command[256];
|
||||
char filename[256];
|
||||
int found = 0;
|
||||
for (int i = 0; i < songCount; i++) {
|
||||
if (SongList[i].id == songId) {
|
||||
sprintf(filename, "%d-%s-%s-%s.mp3",
|
||||
SongList[i].id,
|
||||
SongList[i].artist,
|
||||
SongList[i].name,
|
||||
SongList[i].category);
|
||||
//afplay "/Users/music/song.mp3" &
|
||||
sprintf(command, "afplay \"%s/%s\" & -t 10", MRES_PATH, filename);
|
||||
system(command);
|
||||
printf("正在播放: %s - %s\n", SongList[i].artist, SongList[i].name);
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
printf("未找到ID为 %d 的歌曲,无法播放\n", songId);
|
||||
}
|
||||
ShowPlayQueue();
|
||||
}
|
||||
|
||||
// 播放控制
|
||||
void ControlPlayback(int control) {
|
||||
switch (control) {
|
||||
case 0: // 停止播放
|
||||
system("pkill afplay");
|
||||
printf("播放已停止\n");
|
||||
break;
|
||||
case 1: // 暂停播放
|
||||
system("pkill -STOP afplay");
|
||||
printf("播放已暂停\n");
|
||||
break;
|
||||
case 2://继续播放
|
||||
system("pkill -CONT afplay");
|
||||
printf("继续播放\n");
|
||||
break;
|
||||
case 3: // 下一首
|
||||
system("pkill afplay");
|
||||
if (playQueue.count > 0) {
|
||||
RemoveFirstSong();
|
||||
if (playQueue.count > 0) {
|
||||
PlayMusic(playQueue.songIds[0]);
|
||||
}else {
|
||||
printf("播放歌单已播放完毕,请添加歌曲");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("⚠️输入有误,请重新输入⚠️\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int IsSongFinished() {
|
||||
FILE *fp = popen("ps aux | grep afplay | grep -v grep", "r");
|
||||
if (fp == NULL) {
|
||||
return 0;
|
||||
}
|
||||
char line[256];
|
||||
int isPlaying = 0;
|
||||
while (fgets(line, sizeof(line), fp)) {
|
||||
if (strstr(line, "afplay") != NULL) {
|
||||
isPlaying = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pclose(fp);
|
||||
return isPlaying;
|
||||
}
|
||||
|
||||
|
||||
// 自动播放
|
||||
void AutoPlayNext() {
|
||||
if (playQueue.count > 0) {
|
||||
if (IsSongFinished() == 0) {
|
||||
RemoveFirstSong();
|
||||
if (playQueue.count > 0) {
|
||||
printf("播放完毕,自动切换下一首中。。。\n");
|
||||
PlayMusic(playQueue.songIds[0]);
|
||||
} else {
|
||||
printf("播放队列已空,请继续点歌\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int hasInput() {
|
||||
int result;
|
||||
struct timeval tv = {0, 0};
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(STDIN_FILENO, &fds);
|
||||
result = select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv) > 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
//开始点歌
|
||||
void Start_Muisc() {
|
||||
Read_MuiscFile();
|
||||
if (songCount > 0) {
|
||||
int shown = 0;
|
||||
while (1) {
|
||||
AutoPlayNext();
|
||||
if (!hasInput()) {
|
||||
if (!shown) {
|
||||
printf("\n==================================================\nℹ️ 按回车键继续...\n");
|
||||
shown = 1;
|
||||
}
|
||||
usleep(100000);//0.1秒
|
||||
continue;
|
||||
}
|
||||
shown = 0;
|
||||
printf("\n---------------------👇点歌控制面板👇----------------------\n");
|
||||
printf("1. 添加歌曲到播放队列\n");
|
||||
printf("2. 显示当前播放队列\n");
|
||||
printf("3. 控制播放(0.停止|1.暂停|2.继续|3.下一首):\n");
|
||||
printf("0. 返回主菜单\n");
|
||||
printf("-----------------------👆选择对应数字👆------------------------\n");
|
||||
printf("请输入选择:");
|
||||
int choice;
|
||||
scanf("%d", &choice);
|
||||
while (getchar() != '\n');
|
||||
switch (choice) {
|
||||
case 1: {
|
||||
printf("请输入要播放的歌曲id: \n");
|
||||
int songId;//需要播放的歌曲id
|
||||
scanf("%d", &songId);
|
||||
while (getchar() != '\n');
|
||||
int found = 0;
|
||||
for (int i = 0; i < songCount; ++i) {
|
||||
if (songId == SongList[i].id) {
|
||||
printf("歌曲【%d-%s-%s-%s】已添加到播放队列\n", SongList[i].id, SongList[i].artist, SongList[i].name, SongList[i].category);
|
||||
if (playQueue.count < 100) {
|
||||
// songId = songId - 1;
|
||||
playQueue.songIds[playQueue.count] = songId;
|
||||
playQueue.count++;
|
||||
|
||||
if (playQueue.count == 1) {
|
||||
PlayMusic(songId);
|
||||
}
|
||||
} else {
|
||||
printf("播放队列已满,无法添加更多歌曲\n");
|
||||
break;
|
||||
}
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
printf("未找到ID为 %d 的歌曲\n", songId);
|
||||
}
|
||||
// ShowPlayQueue();
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
ShowPlayQueue();
|
||||
break;
|
||||
case 3: {
|
||||
int control;
|
||||
printf("请输入控制命令 (0.停止|1.暂停|2.继续|3.下一首): ");
|
||||
scanf("%d", &control);
|
||||
while (getchar() != '\n');
|
||||
ControlPlayback(control);
|
||||
break;
|
||||
}
|
||||
case 0:
|
||||
printf("⚠️停止音乐中...⚠️\n");
|
||||
system("pkill afplay");
|
||||
printf("⚠️音乐已停止,返回控制台中...⚠️\n");
|
||||
return;
|
||||
default:
|
||||
printf("无效的选择,请重新输入\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("⚠️找不到歌曲...⚠️\n");
|
||||
}
|
||||
}
|
||||
|
||||
int C3_User() {
|
||||
while (1) {
|
||||
printf("\n---------------------👇用户控制面板👇----------------------\n");
|
||||
printf("1. 歌曲查询\n");
|
||||
printf("2. 歌曲游览\n");
|
||||
printf("3. 开始点歌\n");
|
||||
printf("0.返回控制台\n");
|
||||
printf("-----------------------👆选择对应数字👆------------------------\n");
|
||||
printf("请输入选择:");
|
||||
int opt;
|
||||
scanf("%d", &opt);
|
||||
while (getchar() != '\n');
|
||||
switch (opt) {
|
||||
case 1:
|
||||
Song_query();
|
||||
break;
|
||||
case 2:
|
||||
BrowseSongs();
|
||||
break;
|
||||
case 3:
|
||||
Start_Muisc();
|
||||
break;
|
||||
case 0:
|
||||
printf("⚠️返回主控制台中...⚠️\n");
|
||||
return 0;
|
||||
default:
|
||||
printf("⚠️输入有误,请重新输入⚠️\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
BIN
muisc_message/mres/1-Justin Bieber-sorry-英文.mp3
Normal file
BIN
muisc_message/mres/1-Justin Bieber-sorry-英文.mp3
Normal file
Binary file not shown.
BIN
muisc_message/mres/2-方大同-听-中文.mp3
Normal file
BIN
muisc_message/mres/2-方大同-听-中文.mp3
Normal file
Binary file not shown.
BIN
muisc_message/mres/3-林俊杰-江南-中文.mp3
Normal file
BIN
muisc_message/mres/3-林俊杰-江南-中文.mp3
Normal file
Binary file not shown.
BIN
muisc_message/mres/5-方大同-听2-中文.mp3
Normal file
BIN
muisc_message/mres/5-方大同-听2-中文.mp3
Normal file
Binary file not shown.
BIN
muisc_message/mres/6-方大同-听3-中文.mp3
Normal file
BIN
muisc_message/mres/6-方大同-听3-中文.mp3
Normal file
Binary file not shown.
BIN
muisc_message/mres/7-Justin Bieber-Die for you-英文.mp3
Normal file
BIN
muisc_message/mres/7-Justin Bieber-Die for you-英文.mp3
Normal file
Binary file not shown.
BIN
muisc_message/mres/8-Justin Bieber-Die for you2-英文.mp3
Normal file
BIN
muisc_message/mres/8-Justin Bieber-Die for you2-英文.mp3
Normal file
Binary file not shown.
BIN
muisc_message/mres/9-Justin Bieber-sorry3-英文.mp3
Normal file
BIN
muisc_message/mres/9-Justin Bieber-sorry3-英文.mp3
Normal file
Binary file not shown.
0
muisc_message/mres/demo.txt
Normal file
0
muisc_message/mres/demo.txt
Normal file
13
muisc_message/题目.txt
Normal file
13
muisc_message/题目.txt
Normal file
@ -0,0 +1,13 @@
|
||||
设计并实现一个点歌台管理的C语言程序。3级
|
||||
【功能要求】
|
||||
(1) 管理员功能:
|
||||
歌曲信息管理:歌曲信息添加,查询,修改,删除,存盘,浏览等。
|
||||
歌曲信息至少包括: 编号,歌曲名,歌手名,歌曲类别等。
|
||||
(2) 用户功能:
|
||||
多种类型的歌曲查询、显示功能:
|
||||
按歌曲名、歌手名、歌曲类别等查询歌曲。
|
||||
点歌功能:用户录入歌曲编号,被点播歌曲按点播顺序放入播放表,
|
||||
当全部点播歌曲播放完毕,提示“点播歌曲已经播完,请继续点播”。
|
||||
(3) 设计提示:
|
||||
管理员通过密码登录,进行歌曲的管理。
|
||||
普通用户无需登录,能进行浏览、查询和点歌 操作。歌曲播放及删除,可设计定时器来完成。
|
163
word/C2main.c
Normal file
163
word/C2main.c
Normal file
@ -0,0 +1,163 @@
|
||||
//
|
||||
// Created by CC-star on 25-5-6.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#define Words_File "../word/words.txt"
|
||||
|
||||
struct Words {
|
||||
char English[50];
|
||||
char Chinese[100];
|
||||
// int ReciteIndex;//单词背诵次数【背诵正确+1;错误-1】
|
||||
} wordsList[500];
|
||||
|
||||
int wordsCount,SumRightCount = 0,SumLearnCount = 0;
|
||||
int usedWords[500] = {0};
|
||||
|
||||
// 读取
|
||||
int readWordsFromFile() {
|
||||
FILE* file = fopen( Words_File, "r");
|
||||
if (file == NULL) {
|
||||
printf("\n⚠️无法打开单词库文件:%s⚠️\n", Words_File);
|
||||
return 0;
|
||||
}else {
|
||||
// 单词数
|
||||
wordsCount = 0;
|
||||
char line[100];
|
||||
while (fgets(line, sizeof(line), file) != NULL ) {
|
||||
sscanf(line, "%s %s",wordsList[wordsCount].English, wordsList[wordsCount].Chinese);
|
||||
wordsCount++;
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
if (wordsCount == 0) {
|
||||
printf("\n\t⚠️单词库没有信息⚠️\n");
|
||||
return 0;
|
||||
}else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 显示所有单词
|
||||
void showAllWords() {
|
||||
//readWordsFromFile();
|
||||
printf("\n---------------------👇单词列表👇----------------------\n");
|
||||
for (int i = 0; i < wordsCount; i++) {
|
||||
printf("%d. %s - %s\n", i + 1, wordsList[i].English, wordsList[i].Chinese);
|
||||
}
|
||||
printf("-----------------------👆共计单词数:%d👆------------------------\n",wordsCount);
|
||||
}
|
||||
|
||||
|
||||
// 背单词功能
|
||||
void startLearning() {
|
||||
//readWordsFromFile();
|
||||
int LearnCount,ret;//本次背诵数量
|
||||
char ming[100];
|
||||
int RightCount = 0;//正确数量单词
|
||||
while (1){
|
||||
printf("\n---------------------👇背单词区域👇----------------------\n");
|
||||
printf("请输入要背诵的单词数量(不超过%d): ", wordsCount);
|
||||
ret = scanf("%d", &LearnCount);
|
||||
while(getchar() != '\n');
|
||||
if (ret != 1 || LearnCount < 1 || LearnCount > wordsCount) {
|
||||
do {
|
||||
printf("输入无效,请输入1到%d之间的数字:\n", wordsCount);
|
||||
ret = scanf("%d", &LearnCount);
|
||||
while(getchar() != '\n');
|
||||
}while (ret != 1 || LearnCount < 1 || LearnCount > wordsCount);
|
||||
}
|
||||
// printf("本次需要背诵:%d", LearnCount);
|
||||
|
||||
for (int i = 0; i < LearnCount; i++) {
|
||||
int randomIndex;
|
||||
do {
|
||||
randomIndex = rand() % wordsCount;
|
||||
} while (usedWords[randomIndex] == 1);
|
||||
|
||||
usedWords[randomIndex] = 1;
|
||||
|
||||
printf("单词:%s\n",wordsList[randomIndex].Chinese);
|
||||
printf("请输入对应英文(不要有空格):\n");
|
||||
scanf("%s", ming);
|
||||
while (getchar() != '\n');
|
||||
if (strcmp(wordsList[randomIndex].English, ming) == 0) {
|
||||
RightCount++;
|
||||
} else {
|
||||
printf("错误,对应正确英文是:%s\n",wordsList[randomIndex].English);
|
||||
}
|
||||
}
|
||||
|
||||
printf("-----------------------👆背单词区域👆------------------------\n");
|
||||
printf("\n---------------------👇单次成绩区域👇----------------------\n");
|
||||
//总结提示
|
||||
if (RightCount == LearnCount) {
|
||||
printf("\t太棒啦,全部正确!!本次背了%d个单词,分数为:%d\n",LearnCount,RightCount);
|
||||
}else if (RightCount > (LearnCount/2)){
|
||||
printf("\t不错哦!!本次背了%d个单词,分数为:%d\n",LearnCount,RightCount);
|
||||
}else {
|
||||
printf("\t很遗憾😪,本次背了%d个单词,只正确了%d个\n",LearnCount,RightCount);
|
||||
}
|
||||
printf("-----------------------👆单次成绩区域👆------------------------\n");
|
||||
|
||||
SumLearnCount += LearnCount;
|
||||
SumRightCount += RightCount;
|
||||
RightCount = 0;
|
||||
|
||||
char continueLearning;
|
||||
while (1) {
|
||||
printf("是否继续(Y/N)?\n");
|
||||
scanf(" %c", &continueLearning);
|
||||
if (continueLearning == 'Y' || continueLearning == 'y') {
|
||||
break;
|
||||
} else if (continueLearning == 'N' || continueLearning == 'n') {
|
||||
printf("\n---------------------👇总成绩区域👇----------------------\n");
|
||||
printf("\t本次共计背了%d个单词,总正确数为:%d\n", SumLearnCount, SumRightCount);
|
||||
printf("-----------------------👆总成绩区域👆------------------------\n");
|
||||
SumRightCount = 0;
|
||||
SumLearnCount = 0;
|
||||
return;
|
||||
} else {
|
||||
printf("输入有误,请重新输入\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int C2main() {
|
||||
srand(time(NULL));
|
||||
if (readWordsFromFile() == 1){
|
||||
while (1) {
|
||||
printf("\n---------------------👇背单词控制面板👇----------------------\n");
|
||||
printf("1:开始背单词\n2:查看所有单词\n");
|
||||
printf("0.返回主控制台\n");
|
||||
printf("-----------------------👆选择对应数字👆------------------------\n");
|
||||
printf("请输入选择:");
|
||||
int opt;
|
||||
scanf("%d", &opt);
|
||||
while (getchar() != '\n');
|
||||
switch (opt) {
|
||||
case 1:
|
||||
startLearning();
|
||||
break;
|
||||
case 2:
|
||||
showAllWords();
|
||||
break;
|
||||
case 0:
|
||||
printf("⚠️返回主控制台中...⚠️\n");
|
||||
return 0;
|
||||
default:
|
||||
printf("⚠️输入有误,请重新输入⚠️\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
printf("⚠️背单词程序无法运作,已退出⚠️\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
219
word/words.txt
Normal file
219
word/words.txt
Normal file
@ -0,0 +1,219 @@
|
||||
friend 朋友
|
||||
family 家庭
|
||||
love 爱
|
||||
happiness 幸福
|
||||
laughter 笑声
|
||||
smile 微笑
|
||||
sunshine 阳光
|
||||
rain 雨
|
||||
wind 风
|
||||
cloud 云
|
||||
mountain 山
|
||||
river 河
|
||||
lake 湖
|
||||
ocean 海洋
|
||||
sky 天空
|
||||
earth 地球
|
||||
forest 森林
|
||||
grass 草
|
||||
sand 沙子
|
||||
stone 石头
|
||||
path 路径
|
||||
road 路
|
||||
bridge 桥
|
||||
house 房子
|
||||
tree 树
|
||||
flower 花
|
||||
bird 鸟
|
||||
butterfly 蝴蝶
|
||||
insect 昆虫
|
||||
fish 鱼
|
||||
animal 动物
|
||||
zoo 动物园
|
||||
garden 花园
|
||||
park 公园
|
||||
city 城市
|
||||
country 乡村
|
||||
beach 海滩
|
||||
mountain 山脉
|
||||
valley 谷
|
||||
sunrise 日出
|
||||
sunset 日落
|
||||
night 夜晚
|
||||
morning 早晨
|
||||
afternoon 下午
|
||||
evening 傍晚
|
||||
season 季节
|
||||
spring 春天
|
||||
summer 夏天
|
||||
autumn 秋天
|
||||
winter 冬天
|
||||
weather 天气
|
||||
snow 雪
|
||||
ice 冰
|
||||
heat 热
|
||||
cold 冷
|
||||
windy 有风的
|
||||
rainy 下雨的
|
||||
cloudy 多云的
|
||||
sunny 晴朗的
|
||||
birthday 生日
|
||||
holiday 假日
|
||||
Christmas 圣诞节
|
||||
New Year 新年
|
||||
party 派对
|
||||
music 音乐
|
||||
song 歌曲
|
||||
dance 舞蹈
|
||||
art 艺术
|
||||
painting 绘画
|
||||
sculpture 雕塑
|
||||
poem 诗歌
|
||||
book 书
|
||||
story 故事
|
||||
movie 电影
|
||||
game 游戏
|
||||
play 玩
|
||||
sport 运动
|
||||
football 足球
|
||||
basketball 篮球
|
||||
tennis 网球
|
||||
swimming 游泳
|
||||
running 跑步
|
||||
walking 走路
|
||||
eating 吃
|
||||
drinking 喝
|
||||
cooking 烹饪
|
||||
baking 烘焙
|
||||
reading 阅读
|
||||
writing 写作
|
||||
drawing 画画
|
||||
painting 绘画
|
||||
listening 听
|
||||
watching 看
|
||||
talking 说话
|
||||
laughing 笑
|
||||
crying 哭
|
||||
feeling 感觉
|
||||
thinking 思考
|
||||
dreaming 梦想
|
||||
wishing 希望
|
||||
trying 尝试
|
||||
learning 学习
|
||||
working 工作
|
||||
playing 玩耍
|
||||
traveling 旅行
|
||||
exploring 探索
|
||||
discovering 发现
|
||||
creating 创造
|
||||
building 建造
|
||||
fixing 修理
|
||||
cleaning 清洁
|
||||
organizing 组织
|
||||
decorating 装饰
|
||||
planting 种植
|
||||
harvesting 收获
|
||||
selling 卖
|
||||
buying 买
|
||||
giving 给
|
||||
sharing 分享
|
||||
helping 帮助
|
||||
loving 爱
|
||||
caring 关心
|
||||
teaching 教学
|
||||
understanding 理解
|
||||
remembering 记忆
|
||||
forgetting 忘记
|
||||
knowing 知道
|
||||
believing 相信
|
||||
trusting 信任
|
||||
respecting 尊重
|
||||
honoring 敬重
|
||||
apologizing 道歉
|
||||
forgiving 原谅
|
||||
meeting 见面
|
||||
greeting 问候
|
||||
saying 说
|
||||
listening 倾听
|
||||
hearing 听见
|
||||
seeing 看见
|
||||
looking 看
|
||||
finding 找到
|
||||
searching 搜索
|
||||
seeking 寻找
|
||||
waiting 等待
|
||||
hurrying 匆忙
|
||||
slowing 放慢
|
||||
stopping 停止
|
||||
starting 开始
|
||||
continuing 继续
|
||||
finishing 完成
|
||||
succeeding 成功
|
||||
failing 失败
|
||||
winning 获胜
|
||||
losing 失败
|
||||
competing 竞争
|
||||
cooperating 合作
|
||||
leading 领导
|
||||
following 跟随
|
||||
guiding 指导
|
||||
directing 指挥
|
||||
ordering 命令
|
||||
obeying 服从
|
||||
resisting 抵抗
|
||||
fighting 战斗
|
||||
defending 防御
|
||||
attacking 攻击
|
||||
protecting 保护
|
||||
saving 拯救
|
||||
rescuing 救援
|
||||
hurting 伤害
|
||||
healing 治愈
|
||||
recovering 恢复
|
||||
growing 成长
|
||||
developing 发展
|
||||
improving 改进
|
||||
worsening 恶化
|
||||
changing 改变
|
||||
remaining 保持
|
||||
staying 停留
|
||||
leaving 离开
|
||||
returning 返回
|
||||
arriving 到达
|
||||
departing 离开
|
||||
entering 进入
|
||||
exiting 退出
|
||||
opening 打开
|
||||
closing 关闭
|
||||
breaking 打破
|
||||
fixing 修复
|
||||
building 建设
|
||||
destroying 摧毁
|
||||
making 制作
|
||||
designing 设计
|
||||
planning 计划
|
||||
achieving 实现
|
||||
fulfilling 实现
|
||||
disappointing 令人失望
|
||||
surprising 惊喜
|
||||
shocking 震惊
|
||||
confusing 混乱
|
||||
understanding 了解
|
||||
explaining 解释
|
||||
describing 描述
|
||||
telling 告诉
|
||||
asking 询问
|
||||
answering 回答
|
||||
questioning 质疑
|
||||
doubting 怀疑
|
||||
deciding 决定
|
||||
choosing 选择
|
||||
rejecting 拒绝
|
||||
accepting 接受
|
||||
agreeing 同意
|
||||
disagreeing 不同意
|
||||
arguing 争论
|
||||
debating 辩论
|
||||
negotiating 谈判
|
||||
compromising 妥协
|
||||
solving 解决
|
Loading…
x
Reference in New Issue
Block a user