关于C语言设计一个系统完成音乐文管理基本业务

一、功能设计

(1) 每个文件内容包括音乐编号、歌名、专辑、歌手、作曲、作词,文件路径;

(2) 建立适当的查找表以提高查找效率;

(3)实现查找表的插入删除操作;

(4) 设计高效的查找算法实现高效歌曲检索


二、实现代码

/*
 *  Music File Manager  —— 哈希索引 + 文本 CSV 持久化
 *  gcc music_mgr.c -o music_mgr
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#ifdef _WIN32
#include <windows.h>
#define CLEAR "cls"
#else
#define CLEAR "clear"
#endif

#define HASH_SIZE   2048     /* 哈希桶数,2 的幂次 */
#define MAX_LEN     256
#define CSV_FILE    "music.csv"

typedef struct Music {
    int  id;                           /* 音乐编号 主键 */
    char title    [MAX_LEN];           /* 歌名 */
    char album    [MAX_LEN];
    char artist   [MAX_LEN];
    char composer [MAX_LEN];
    char lyricist [MAX_LEN];
    char path     [MAX_LEN];           /* 绝对文件路径 */
    struct Music *next_id;             /* 编号哈希链 */
    struct Music *next_title;          /* 歌名哈希链 */
    struct Music *next_artist;         /* 歌手哈希链 */
} Music;

/* 三个哈希表头 */
static Music *hash_id[HASH_SIZE];
static Music *hash_title[HASH_SIZE];
static Music *hash_artist[HASH_SIZE];

/* ====================== 哈希函数 ====================== */
static unsigned int hash_int(int key) {
    return (unsigned)key & (HASH_SIZE - 1);
}
static unsigned int hash_str(const char *s) {
    unsigned h = 0;
    while (*s) h = h * 31 + tolower(*s++);
    return h & (HASH_SIZE - 1);
}

/* ====================== 工具函数 ====================== */
void pause_key() {
    puts("\n按回车键继续...");
    getchar();
}
char *trim_newline(char *s) {
    s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值