Simple File Operations

Source: Internet
Author: User
1 # include <stdio. h> 2 3 int main () 4 {5 file * fp = fopen ("hello", "W +"); 6 if (FP = NULL) {7 perror ("fopen"); 8 return 1; 9} 10 11 char * P = NULL; 12 char * buff = "Hello boy! "; 13 14 int ret = fputs (buff, FP); // write the content to the file for 15 if (Ret <0) {16 perror (" fputs "); 17 return 1; 18} 19 20 fseek (FP, 0, seek_set); // point the file pointer to the header, because the value has already pointed to the last 21 22 unsigned char arr [1024] = {0}; // This array is used to store the 23 p = fgets (ARR, 1024, FP); 24 if (P = NULL) {25 perror ("fgets"); 26 return 1; 27} 28 printf ("% s \ n ", ARR); 29}
  1. Fopen is a file that defines a file pointer.
  2. Fputs writes strings to files.
  3. Then, fgets is included in the file to the character array and output.

    

Simple File Operations

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.