Parsing of LRC lyrics in C Language

Source: Internet
Author: User
 You can only paste the  Code . Please note: 
# Include <stdio. h> # include <string. h> # include <assert. h> # define strlen 256 // only remove the time mark char * parse_lrc_line (char * Line) {char * P = NULL; P = strrchr (line, ']'); if (P = NULL) {goto end;} p = p + 1; end: Return P;} // parse the string of the LRC file containing the time tag in it, and output it to stdout. Slight modification is of practical value (encoding or modification) void parse_lrc_line2 (char * Line) {char * P = NULL; char * Right = NULL; char * Left = NULL; char buff [strlen] = {0}; char * P2 = NULL; int N; P = line; // le FT is the left [location left = strchr (p, '['); If (Left = NULL) {return ;} // right is the right] location right = strchr (p, ']'); While (right! = NULL & left! = NULL) {n = right-left-1; strncpy (buff, left + 1, n); puts (buff); P2 = strrchr (p, ']'); if (P2! = NULL) {P2 ++; puts (P2) ;}// you can save the lyrics and time tag information here. The time tag is buff, the lyrics are P2 // here, the buff is cleared to \ 0 .. In this case, you do not need to calculate the string length and add \ 0 to memset (buff, '\ 0', n); P = right; // The strchr function only searches backward, divide this string into two types: * P = '\ 0'; P = p + 1; left = strchr (p,' ['); If (Left = NULL) {continue;} Right = strchr (p, ']') ;}} int main () {file * f = NULL; char line [strlen] = {0 }; F = fopen ("qclg. LRC "," R "); Assert (f); While (fgets (line, strlen, f )) {// parse_lrc_line is the printf (parse_lrc_line (line);} rewind (f); // read each row and parse while (fgets (line, strlen, f) {// parse_lrc_line2 (line);} getchar (); fclose (f );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.