This program separates the Time of the lyrics file from the lyrics file, and converts the time to the unit of microseconds.
# Include <stdio. h> # include <stdlib. h> # include <string. h> # include <ctype. h> # define maxline 256 # define maxbuf 256 char * TMP; int chartoint (char ch) {return ch-'0';} int strtoint (char * Str) {// computing time, microsecond if (isdigit (STR [0]) & isdigit (STR [1]) & isdigit (STR [0]) & isdigit (STR [0]) & isdigit (STR [0]) & isdigit (STR [0]) {int mintue = chartoint (STR [0]) * 10 + chartoint (STR [1]); int second = chartoint (STR [3]) * 10 + Chartoint (STR [4]); int microsecond = chartoint (STR [6]) * 10 + chartoint (STR [7]); Return (mintue * 60 + second) * 1000 + microsecond * 10;} return-1;} Char * praselrc (char * STR, int * Time) {If (strlen (STR) = 0) {// empty row return NULL;} else {char * P, * temp; P = strchr (STR, '['); If (P! = NULL) if (isdigit (* (p + 1) {temp = p + 1; P = strchr (STR, ']'); temp [p-Temp] = '\ 0'; // printf ("% s \ n", temp); If (* time = strtoint (temp) <0) {perror ("error time"); exit (1);} TMP = p + 1; while (* P! = '\ N') {P ++;} TMP [p-TMP] =' \ 0'; // printf ("% s", LRC); Return TMP ;} return NULL;} int main () {char Buf [maxline]; file * FD; int time [maxbuf]; int line = 0; char * LRC [maxbuf]; TMP = (char *) malloc (sizeof (char) * maxline); If (TMP = NULL) {perror ("malloc Buf Err "); return 1;} // FD = fopen ("Li xiaozhe-love does not need a reason. LRC "," R "); // FD = fopen (" longmeizi-who did you give love. LRC "," R "); FD = fopen (" Wang ninglu-the illusion of tears. LRC "," R "); If (FD = Null) {perror ("Open File"); exit (1) ;}while (fgets (BUF, sizeof (BUF), FD )! = NULL) {If (LRC [Line] = praselrc (BUF, & time [Line])! = NULL) {printf ("% d \ t % s \ n", time [Line], LRC [Line]); line ++ ;}} return 0 ;}
Due to horizontal restrictions, only files in Figure 1 format can be parsed, while files in Figure 2 format cannot.
After running this program, the time and lyrics are stored in two arrays respectively. The running result is as follows: