Operation of files in C language

Source: Internet
Author: User

The so-called "file" refers to an ordered set of related data. This dataset has a name, called the file name. In fact, in the previous chapters we have used the files many times, such as source program file, target file, executable file, library file (header file ) and so on. files usually reside on external media , such as disks , and are only transferred into memory when they are used.

Example one: Reading the contents of a file

#include <stdio.h>intMain () {FILE*FP; Charch; if((Fp=fopen ("D:\\c1.txt","RT"))==NULL) {printf ("\ncannot Open File strike any key exit!");    Getch (); Exit (1); } CH=fgetc (FP);  while(ch!=eof)//Ch is a character, one of them is taken out{putchar (ch); CH=FGETC (FP);//reads a character from the file pointed to by the file pointer stream, reads a byte, and then moves the cursor position one byte after the other. } fclose (FP);}

Operation of files in C language

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.