File system: Read, file does not exist then create

Source: Internet
Author: User

1#include <stdio.h>2#include <stdlib.h>3 #define"Save.txt"4 intMainintargcintargv[])5 {6FILE *fp_read,*Fp_write;7     8Fp_read=fopen (The,"r+");9     Ten     if(fp_read==NULL) One     { APuts"Not exist,create now"); -Fp_write=fopen (The,"w+"); -         if(fp_write==NULL) thePuts"Create failed"); -         Else -         { -Puts"Create succeed"); +Fputs"good\n", Fp_write);//Write file: Return non-negative value on success, EOF on Failure -Fflush (Fp_write);//storing data in a cache in a document +Fp_read=Fp_write; AFseek (Fp_write,0, Seek_set);//move cursor to end of file: Seek_end, beginning of file: Seek_set at              -         } -     } -     Else -Puts"Open succeed"); -  in     //Print File Contents -Rewind (Fp_read);//move the cursor to the beginning of the file to     intCH =0; +      while((Ch=fgetc (fp_read))! =EOF) - Putchar (CH); the  *System"Pause"); $ Panax Notoginseng  -}

File system: Read, file does not exist then create

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.