資源簡介
使用c語言中的鏈表,字符分割,while,for等各種功能制作的歌詞解析源程序,可完美解析大部分的lrc歌詞。
代碼片段和文件信息
#include?
#include?“LRC.h“
#include?“unistd.h“
#include?
struct?lrc?
{
int?Time;
char?LrcText[100];
struct?lrc?*next;
};
?
int?main()
{?
FILE?*fd;
int?sizersize;
char?*pbuffer;
struct?lrc?*?head;
unsigned?int?num?=?0;
int?minute?=0?second?=?0msecond=0;
if(?(fd?=?fopen(“smlove.lrc““r+“))?==?NULL?)
printf(“No?Lrc?File!\n“);
else
{?
fseek(fd02);
size?=?ftell(fd);
rewind(fd);
pbuffer?=?(char?*)malloc(size+1);?
rsize?=?fread(pbuffer1sizefd);
fclose(fd);
*(pbuffer+rsize)=‘\0‘;
}
Message_Song(pbuffer);
head?=?GetLrcInfo(pbuffer?size);
printf(“%s“head->LrcText);
head=head->next;
while(1)
{
sleep(1);
while?(?second++?==?60?)
{
second=0;
while(minute++?==60)
minute=0;
}
if?(head?==?NULL)
{
printf(“the?end\n“);
}
if(?(head?!=?NULL)?&&?(head->Time?==?minute*60+second-1)?)
{
printf(“%s\n“head->LrcText);
head=head->next;
}
}
free(pbuffer);
}
struct?lrc?*GetLrcInfo(char?*LrcFile?unsigned?int?FileSize)
{
char?*pb*mid*head;
struct?lrc?*pnew;????//當前位置
char?temp[100];
????int?i=0j=0;
int?count=0getline=0;
struct?lrc?*pp;
pp=(struct?lrc?*)malloc(?sizeof(struct?lrc));
pp->Time=0;
strcpy(pp->LrcText“designed?by?劉桐\n“);
pp->next=NULL;//建立空鏈表;
head?=?pb?=?LrcFile;
while?(?(*pb?!=?‘[‘)?||?(*(pb+6)?!=?‘.‘)?)
{
pb++;
}
while?(?(pb?-?head)?!=?FileSize??)
{
while?(?*pb?!=?‘\n‘)
{
temp[i]?=?*pb;
pb++;
i++;
}
pb++;
temp[i]=‘\0‘;
mid=temp;
for?(j=0;j {
if?(?temp[j]?==?‘.‘)
{
count++;
}
}
getline=count;
pnew=(struct?lrc?*)malloc(?sizeof(struct?lrc));
strcpy(pnew->LrcTextmid+count*10);
pnew->Time?=?atoi(mid+1)*60+atoi(mid+4)
- 上一篇:傳播c++.txt
- 下一篇:基于可視化界面實現Ping命令
評論
共有 條評論