我无法从.srt(字幕)文件中提取时间并将其写入另一个名为 output.srt 的文件。当我运行以下命令时,我会在输出文件中写入一些时髦的东西。
// 其中 hr=hours,mn=minutes,sc=seconds,ms=mili seconds
#include <stdio.h>
#define LINES 50
#define CHARAC 80
int main(void){
FILE *in;
FILE *out;
char text[LINES][CHARAC];
char timings[LINES][CHARAC];
int i=0,lines=0,items=0;
int hr=0,mn=0,sc=0,ms=0,hr2=0,mn2=0,sc2=0,ms2=0;
in=fopen("file2.srt","r");
out=fopen("output.srt","w");
while (!feof(in)){
fgets(text[i],80,in);
items=sscanf(text[i],"%d:%d:%d,%d --> %d:%d:%d,%d ",&hr,&mn,&sc,&ms,&hr2,&mn2,&sc2,&ms2);
//------------------------------------->edited<----------------------------------
switch (items)
{
case 1: break;
case 8:
sprintf(timings[i],"%d:%d:%d,%d --> %d:%d:%d,%d",hr,mn,sc,ms,hr2,mn2,sc2,ms2);
break;
case 0: break;
}
//------------------------------------->edited<----------------------------------
++i;
}
lines=i;
for (int i=0;i<lines;i++){
fprintf(out,"%s\n",timings[i]);
}
fclose(in);
fclose(out);
return 0;
}
我该如何提取前 10 个时间?