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.

Pranathi said:   8 years ago
'fclose()' takes only one argument at a time i.e it can't be used to close multiple opened file at a time.
(3)

Pratyush sharma said:   3 years ago
Option D will be the Right answer because you can not pass more than one argument in function.
(1)

Vivek Shivhare said:   10 years ago
Yes it is true to write "return (a, b, c)" it will returns the right most value (e.g c).

The reason is return and fclose both are predefined functions theirs properties are designed by devlopers. Which are different.

fclose is file operation function so it is different than return.
(1)

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?

Snegha m d said:   1 year ago
The correct answer is D.

Rajan said:   5 years ago
@All.

The code should be;

#include<stdio.h>
int main ()
{
FILE *fs, *ft, *fp;
fp = fopen("ABC", "r");
fs = fopen("ACD", "r");
ft = fopen("ADF", "r"); = fclose(fp, fs, ft);
return 0;
}
A - "ABC"
B- "ACD"

Venkat said:   7 years ago
Please explain it in a simple way.

Yuvasree said:   9 years ago
Yes, correct answer is D, It will get error message as too many arguments to function fclose. Because according fclose syntax we can pass only one argument.

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.

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


Post your comments here:

Your comments will be displayed after verification.