Home / C Programming / Input / Output :: Discussion

Discussion :: Input / Output

  1. Point out the error/warning in the program?

     #include
    
      int main()
      {
         unsigned char ch;   
         FILE *fp;  
         fp=fopen("trial", "r");     
         while((ch = getc(fp))!=EOF)         
             printf("%c", ch);     
         fclose(fp); 
         return 0; 
     } 
    

  2. A.

    Error: in unsigned char declaration

    B.

    Error: while statement

    C.

    No error

    D.

    It prints all characters in file "trial"

    View Answer

    Workspace

    Answer : Option A

    Explanation :

    Here, EOF is -1. As 'ch' is declared as unsigned char it cannot deal with any negative value.


Be The First To Comment