C Programming - Input / Output - Discussion
Discussion Forum : Input / Output - Point Out Errors (Q.No. 1)
1.
Point out the error in the program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned char;
FILE *fp;
fp=fopen("trial", "r");
if(!fp)
{
printf("Unable to open file");
exit(1);
}
fclose(fp);
return 0;
}
Answer: Option
Explanation:
This program tries to open the file trial.txt in read mode. If file not exists or unable to read it prints "Unable to open file" and then terminate the program.
If file exists, it simply close the file and then terminates the program.
Discussion:
17 comments Page 2 of 2.
Prashant Choudhary said:
1 decade ago
A is correct in any modern compiler. Please do not rely on turbo c.
Chandu said:
1 decade ago
What do you mean by unsigned char; in this program ?
Chris said:
1 decade ago
Tried it in the MS compiler, A is correct!
Aditi said:
6 years ago
Can anyone explain line by line execution?
Abc said:
1 decade ago
Char is keyword. It cannot be redeclared.
Abhimanyu said:
1 decade ago
It gives error with code blocks.
(1)
Kaushik said:
1 decade ago
It gave error in DEV C++ also.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers