Use a CSV suffix file as the configuration file

Source: Internet
Author: User
Tags dotnet

InProgramWhen the CSV suffix file is used as the configuration file during design, it is particularly convenient to edit the configuration file.CodeTo demonstrate how to write and read data.

1. Write files

When writing a file, use the fprintf function to write data, and use commas to separate the attributes of each configuration file.

File * _ dbfile = fopen ("D:/dotnet.csv", "W ");
If (_ dbfile)
{
// Write a file
Fprintf (_ dbfile, "A, B, C, D, E, F, GDD ");
Fclose (_ dbfile );
}

2. Read files

When reading a file, you can use the fgets function to read the data in each row in the _ Buf function.
Char _ Buf [500];
File * _ dbfile2 = fopen ("D:/dotnet.csv", "R ");
If (_ dbfile2)
{
// Read from the file
Fgets (_ Buf, 499, _ dbfile2 );
Fclose (_ dbfile2 );
}

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.