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 1 of 2.
Aditi said:
6 years ago
Can anyone explain line by line execution?
Aditya Dixit said:
8 years ago
In my GCC Compiler, it is showing error. The answer should the option (a). If anyone from the Website is seeing this please review the Answer again.
Vidya said:
8 years ago
It is showing error in my compiler. How the answer is 'c' instead of 'a'?
Please explain me.
Please explain me.
Amit Saxena said:
9 years ago
I found the option [A] correct. How can a declaration remain incomplete without var?
Faraz Ahmad Ramish said:
1 decade ago
When there is no extension given along with file name then how come trail.txt in explanation?
Swapnil said:
1 decade ago
Depends on compiler to compiler.
In Turbo C it will give error to unsigned char;.
In Turbo C it will give error to unsigned char;.
(1)
Gangadhar said:
1 decade ago
Option A is correct.
unsigned char; //this is wrong.
A compilation error due to bad syntax of declaration.
unsigned char; //this is wrong.
A compilation error due to bad syntax of declaration.
Prashant Choudhary said:
1 decade ago
A is correct in any modern compiler. Please do not rely on turbo c.
Abhimanyu said:
1 decade ago
It gives error with code blocks.
(1)
Veena Sameera said:
1 decade ago
Why the compilation of a program from one compiler to another compiler varies (some times) ? we need output which accepts globally. But in some perspectives it may not.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers