[Note] when reading files in C Language fgets, pay attention to the end character of each line.

Source: Internet
Author: User

The procedure is as follows:


Void gets_line (MYSQL * conn_ptr)

{

FILE * fp;

Char line [60];


Fp = fopen ("test.csv", "r ");

If (fp = NULL)

Printf ("Error opening file! \ N ");

Else

Printf ("Opened! \ N ");


While (fgets (line, 60, fp )! = NULL)

{

Line [strlen (line)-1] = '\ 0'; // do not miss a line break;

Printf ("% s \ n", line );

}

Fclose (fp );

}


When viewing the output file, you need to display the terminator to check whether the content of the string 'line' meets the requirements, because the line break of the txt file is '\ r \ n ', most programs end with '\ n.


In Notepad ++:

650) this. width = 650; "src =" http://img1.51cto.com/attachment/201308/072149242.png "title =" temp2k.png "/>

Something amazing will happen!


Related Article

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.