Reading, outputting, and saving file content using file streams [abandon Sina Blog]

Source: Internet
Author: User

I have always felt that the part of the file stream in the book is more ugly than A Dream of Red Mansions. I have never understood this problem for almost two years. Today, we have finally solved a part of the problem. It is indeed a leap in terms of "quality.
/*
I want to write a program to read and output the file content to the display and save the file content to a file named Zhaos. renye file (in Linux, the suffix does not matter ). Start to implement
*/

# Include <iostream. h> 〉
# Include
Int main (){
File * FP, * Zhaos:
// Open the file
Fp = fopen ("a.txt", "R "):
If (FP = NULL)
{

Printf ("file open erroe! \ N "); exit (0 );
}
Char C;
While (1)
{
C = fgetc (FP); putc (C, FP );
} Fcloese (FP); fcloese (Zhaos );
Return 0:
}// Open the Zhaos file to display the content of the FP file. //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////////////////// The following output specific content is saved to a file.
# Include <stdio. h> int main () {file * FP; FP = open ("zhoas.txt", "W"); If (! FP) {printf ("Open error! "); Exit) (0);} int I; for (I = 0; I <10000; I ++) fprintf (FP," % d \ n ", i); fclose (FP); Return 0;} // click here to open the zhaos.txt file, which is 1 ~ All numbers of 10000

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.