C Programming - Input / Output - Discussion

Discussion Forum : Input / Output - General Questions (Q.No. 6)
6.
Which files will get closed through the fclose() in the following program?
#include<stdio.h>

int main()
{
    FILE *fs, *ft, *fp;
    fp = fopen("A.C", "r");
    fs = fopen("B.C", "r");
    ft = fopen("C.C", "r");
    fclose(fp, fs, ft);
    return 0;
}
"A.C" "B.C" "C.C"
"B.C" "C.C"
"A.C"
Error in fclose()
Answer: Option
Explanation:

Extra parameter in call to fclose().

Discussion:
27 comments Page 1 of 3.

Bhanu Prakash said:   1 decade ago
The the correct option is C. "A.C"
there can be any no. of arguments passed to fclose.
But which file is closes depends on the functionality of the comma(,) operator. It takes the first argument.

Riya said:   1 decade ago
Please tell the correct answer (C) or (D). ?

Gayathri said:   1 decade ago
The correct option is D only.
because the syntax of fclose is int fclose(FILE *stream); and we cannot use separator(,) in this.
if you use separator it will return an error as Extra parameter in call to fclose().

Apurva Nigam said:   1 decade ago
Inbuilt function fclose has a prototype fclose(FILE *stream) that is it can have only one parameter passed to it.

Take a simple example:-
u have a function "func(int);".
Now u cant call this function as
func();
or
func(i,j,k);

Function call should match with its prototype...
Take care :)

Cheran said:   1 decade ago
Because we cannot give many parameters inside fclose().

Silome jain said:   1 decade ago
Please tell about all file function, why we use it, what its purpuse to use.

Vanita said:   1 decade ago
How? can you explain it clearly?

Irresistiblegal said:   1 decade ago
The correct option id D coz..
syntax of fclose is-

#include <stdio.h>
int fclose( FILE *stream );

The function fclose() closes the given file stream, deallocating any buffers associated with that stream. fclose() returns 0 upon success, and EOF otherwise.

thats why when we give too much parameter inside fclose() it gives error-too many arguments to function 'fclose'.

Aakash said:   1 decade ago
fclose() can close only one file at a time. If more than 1 argument than it will take only first and ignore rest.

Leenaja said:   1 decade ago
To close all the files opened with fopen()at a time, we can use file function closeall(). This function has no arguments.


Post your comments here:

Your comments will be displayed after verification.