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;
}
Error: in unsigned char statement
Error: unknown file pointer
No error
None of above
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.

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.

Abc said:   1 decade ago
Char is keyword. It cannot be redeclared.

Guru said:   1 decade ago
Syntax is correct but unsigned int leads to infinite loop while checking EOF(-1).

Chandu said:   1 decade ago
What do you mean by unsigned char; in this program ?

Ivo said:   1 decade ago
It works in Turbo C, but only if declared at the beginning of main...

Kaushik said:   1 decade ago
It gave error in DEV C++ also.

Muthu said:   1 decade ago
Does unsigned char is correct? Will it work in TurboC compiler? But is works in gcc compiler too ?


Post your comments here:

Your comments will be displayed after verification.