IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Input / Output - Discussion

@ : Home > C Programming > Input / Output > Point Out Errors - Discussion

Read more:

"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.


Chris said: (Wed, May 11, 2011 02:19:58 AM)    
 
Tried it in the MS compiler, A is correct!

Muthu said: (Wed, Aug 3, 2011 11:40:30 PM)    
 
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.

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!