C language File read/write operation, write data to file

Source: Internet
Author: User


Very early written in the Linux system file read and write operations, write data to the file, very time for beginners to learn

#include <stdio.h>int writeinfotofile (const char *strfile) {int age, I;char name[10]; File *FP;FP = fopen (strfile, "w");//read-only mode open if (fp = = NULL) {perror ("fopen");//File open failed, print error message return-1;} for (i=0; i<3; i++)//write Data {printf ("Iput Age and Name:\n"), scanf ("%d%s", &age, Name), fprintf (FP, "%d,%s\n", age, Nam e);} Fclose (FP);//Close File}int main () {char file[20] = "Data.txt"; writeinfotofile (file);//system ("CP file Data.csv");}


C language File read/write operation, write data to file

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.