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 2 of 3.

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.

Yogesh thuwal said:   1 decade ago
While fclose() read only one argument. Then we pass to the 3 files that time it will close 1 one.

Rocks said:   1 decade ago
@Bhanu prakash.

You telling that it takes the first argument. Simply you are making fool to c compilers because any compiler may be turbo c or gcc it read from the right to left. Any it leave the extra parameter.

R. rajkumar... said:   1 decade ago
Can we close some selected file at a time from the many no of files by use of fclose or any other method?

Shilpa said:   1 decade ago
We can use fcloseall(); then all the opened files will be closed.

Ashwini said:   1 decade ago
M getting segmentation fault even though m passing 1 parameter to it, can any 1 fix this problem?

Vamsi Tharun Kumar said:   1 decade ago
Answer is 'D', Because comma operator used in the expression fclose (fp, fs, ft). The comma operator has left-right associativity. The left operator is always evaluated first, and the result of evaluation is discarded before the right operand is evaluated.

Anu said:   1 decade ago
Please explain then how to print fp fs ft?

K Srinivas Pavan Kumar said:   1 decade ago
We can close any number of files by using a function fcloseall().

Kumar harsh said:   1 decade ago
Can any body tell when fclose (a, b, s) is false then is it true return (a, b, c)?

Please tell me in detail.


Post your comments here:

Your comments will be displayed after verification.