歌词解析: 解析到每一行的歌词,添加延时函数
This commit is contained in:
@@ -4,7 +4,7 @@ BIN_DIR := ../bin
|
||||
CC = gcc
|
||||
TARGET = $(BIN_DIR)/main
|
||||
# SRC = $(SRC_DIR)/lrc.c $(SRC_DIR)/console.c $(SRC_DIR)/start_mplayer.c $(SRC_DIR)/main.c
|
||||
OBJ = $(OBJ_DIR)/lrc.o $(OBJ_DIR)/console.o $(OBJ_DIR)/start_mplayer.o $(OBJ_DIR)/main.o
|
||||
OBJ = $(OBJ_DIR)/lrc.o $(OBJ_DIR)/console.o $(OBJ_DIR)/start_mplayer.o $(OBJ_DIR)/time_delay.o $(OBJ_DIR)/main.o
|
||||
|
||||
# $(OBJ_DIR)/%.o: %.c
|
||||
# $(CC) -c $< -o $@
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef __TIME_DELAY_H__
|
||||
#define __TIME_DELAY_H__
|
||||
|
||||
// 自封装延时函数
|
||||
void time_delay(int sec);
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "./includes/lrc.h"
|
||||
#include "./includes/console.h"
|
||||
#include "./includes/start_mplayer.h"
|
||||
#include "includes/time_delay.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -27,5 +28,26 @@ int main()
|
||||
return -1; // 为歌词数据分配内存失败,退出程序
|
||||
}
|
||||
|
||||
// 读入歌词内容
|
||||
fread(lrc_mem_data, lrc_size, 1, fp); // 读入歌词数据
|
||||
// printf("%s", lrc_mem_data);
|
||||
// FILE *fwx = fopen("../lrc/简单爱copy.lrc", "w");
|
||||
// fwrite(lrc_mem_data, lrc_size, 1, fwx);
|
||||
|
||||
// 逐行解析歌词
|
||||
char *line = strtok(lrc_mem_data, "\r\n"); // 逐行解析歌词
|
||||
int i = 1;
|
||||
while (line != NULL)
|
||||
{
|
||||
time_delay(2);
|
||||
printf("%d.\t%s\n", i++, line);
|
||||
line = strtok(NULL, "\r\n");
|
||||
}
|
||||
// FILE *fwx = fopen("../lrc/简单爱copy.lrc", "wb");
|
||||
// fwrite(lrc_mem_data, lrc_size, 1, fwx);
|
||||
|
||||
// 释放内存,关闭文件
|
||||
free(lrc_mem_data); // 释放歌词数据内存
|
||||
fclose(fp); // 关闭歌词文件
|
||||
return 0;
|
||||
}
|
||||
@@ -1,26 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "includes/time_delay.h"
|
||||
void time_delay(int sec)
|
||||
{
|
||||
int s_time,e_time;
|
||||
s_time=time(NULL);
|
||||
while(1)
|
||||
int s_time, e_time;
|
||||
s_time = time(NULL);
|
||||
while (1)
|
||||
{
|
||||
e_time=time(NULL);
|
||||
if(e_time==s_time+sec)
|
||||
e_time = time(NULL);
|
||||
if (e_time == s_time + sec)
|
||||
break;
|
||||
}
|
||||
}
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
printf("hello world\n");
|
||||
time_delay(3);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// int main(int argc, char *argv[])
|
||||
// {
|
||||
// while(1)
|
||||
// {
|
||||
// printf("hello world\n");
|
||||
// time_delay(3);
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user