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;
}
Answer: Option
Explanation:
Extra parameter in call to fclose().
Discussion:
27 comments Page 1 of 3.
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'.
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'.
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 :)
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 :)
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"
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"
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.
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)
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.
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.
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.
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().
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().
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.
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.
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.
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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers