Computer Science, asked by smdyaseen1008, 1 year ago

Explain fopen ( ) and fclose ( ) file handling functions.

Answers

Answered by luk3004
6

ile operation

Declaration & Description

fopen() Declaration: FILE *fopen (const char *filename, const char *mode)

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() Declaration: int fclose(FILE *fp);

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);


Answered by amishasingh2311
0

Explanation:

C Programming language offers inbuilt functions for handling the files such as fopen(), fclose(), gets() and fputs() etc.

fopen file handling function-

In C Programming language fopen() function is used to open a file and perform operations like reading or writting etc.If the mentioned file name does not exist this function fopen() createsa new file. We can declare a file pointer and use fopen() file handling function as given below:

FILE *fp;

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

Here,

  • fp =  is the file pointer to the data type -'File'
  • filename = actual file name with full path
  • mode = operation that will be performed on the given file.

There are various modes of operations like  r, w, a, r+, w+ and a+.

r – Opens the file in read mode and sets the pointer to the first character present in the file. It returns null if such file does not exist.

w – Opens a file in write mode. It returns null if file could not be opened. If file exists, data are overwritten.

a – Opens a file in append mode.  It returns null if file couldn’t be opened.

r+ – Opens a file for read and write mode and sets pointer to the first character in the file.

w+ – opens a file for read and write mode and sets pointer to the first character in the file.

a+ – Opens a file for read and write mode and sets pointer to the first character in the file. But, it can’t modify existing contents.

fclose file handling function:

Declaration: int fclose(FILE *fp);

fclose() closes that file which the file pointer points or the opened file. In a program we can close a file as given below:

fclose (fp);

Learn more:

https://brainly.in/question/48154289?referrer=searchResults

https://brainly.in/question/12153387?referrer=searchResults

Similar questions