0% found this document useful (0 votes)
69 views7 pages

C File Handling Basics

1. In C, all input and output is done through streams which are sequences of bytes of data flowing into or out of a program. 2. Functions like fopen(), fclose(), gets(), and fputs() are used for file handling in C. 3. fopen() is used to open a file and returns a file pointer, fclose() closes an open file, gets() reads a string from stdin, and fputs() writes a string to a file.

Uploaded by

Uma Mahesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views7 pages

C File Handling Basics

1. In C, all input and output is done through streams which are sequences of bytes of data flowing into or out of a program. 2. Functions like fopen(), fclose(), gets(), and fputs() are used for file handling in C. 3. fopen() is used to open a file and returns a file pointer, fclose() closes an open file, gets() reads a string from stdin, and fputs() writes a string to a file.

Uploaded by

Uma Mahesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

In C all input and output is done with streams

2. Stream is nothing but the sequence of bytes of data

3. A sequence of bytes flowing into program is called input stream

4. A sequence of bytes flowing out of the program is called output stream

fopen(), fclose(), gets(), fputs() functions in C


fopen(), fclose(), gets() and fputs() functions are file handling functions in C programming language. Please find
below the description and syntax for each above file handling functions.

fopen()

fopen()fopen() function is used to open a file to perform operations such as reading, writing etc. In a C program, we
declare a file pointer and use fopen() as below. fopen() function creates a new file if the mentioned file name does
not exist.

FILE *fp;

fp=fopen (“filename”, ”‘mode”);

Where,
fp – file pointer to the data type “FILE”.

filename – the actual file name with full path of the file.

mode – refers to the operation that will be performed on the file. Example: r, w, a, r+, w+ and a+. Please refer
below the description for these mode of operations

fclose()

fclose() function closes the file that is being pointed by file pointer fp. In a C program, we close a file as
below.

fclose (fp);

fscanf(fp,”format specifiers”,arguments);

You might also like