Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Fopen, Fclose, Gets, Fputs Functions in C

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 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