"I never think of the future. It comes soon enough."
- Albert Einstein
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;
}
[A].
Error: in unsigned char statement
[B].
Error: unknown file pointer
[C].
No error
[D].
None of above
Answer: Option C
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.
Does unsigned char is correct? Will it work in TurboC compiler? But is works in gcc compiler too ?
Kaushik said:
(Mon, Aug 22, 2011 02:45:55 AM)
It gave error in DEV C++ also.
Ivo said:
(Thu, May 31, 2012 08:07:29 AM)
It works in Turbo C, but only if declared at the beginning of main...
Chandu said:
(Fri, Jul 20, 2012 11:56:03 PM)
What do you mean by unsigned char; in this program ?
Guru said:
(Mon, Sep 24, 2012 12:59:34 AM)
Syntax is correct but unsigned int leads to infinite loop while checking EOF(-1).
Abc said:
(Thu, Sep 27, 2012 06:17:35 PM)
Char is keyword. It cannot be redeclared.
Veena Sameera said:
(Tue, Dec 4, 2012 10:52:59 AM)
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.