Review C language-File Operations

Source: Internet
Author: User

Review C language-File Operations

# Include

 
  
# Include

  
   
Int main () {char buf [64] = "hello word! "; // Open the FILE to read the FILE information. Output/* FILE * fp = fopen ("./file1 "," r "); if (! Fp) {perror ("An error occurred while opening the file! "); Exit (-1);} // char buf [64] = {''}; size_t num = fread (buf, fp ); printf ("% d % s \ n", num, buf); fclose (fp); * // Write FILE Information/* FILE * fp2 = fopen (". /file1 "," w "); if (! Fp2) {perror ("An error occurred while opening the file! "); Exit (-1);} // char buf [64] =" hello world "; fwrite (buf, 1, 64, fp2); fclose (fp2 ); * /// read the content in FILE 1 to FILE * fp3 = fopen (". /file1 "," r "); if (! Fp3) {perror ("An error occurred while reading the file! "); Exit (-1);} FILE * fp4 = fopen ("./file2 "," w "); if (! Fp4) {perror ("An error occurred while reading the file! "); Exit (-1);} while (1) {size_t num = fread (buf, 1, 20, fp3); if (num <= 0) {break ;} fwrite (buf, 1, num, fp4);} fclose (fp3); fclose (fp4); return 0 ;}

  

 

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.