Home / C Programming / Input / Output :: Point Out Correct Statements

C Programming :: Input / Output

  1. Which of the following statement is correct about the program?

     #include
     
      int main() 
      {   
          FILE *fp;   
          char ch;    
          int i=1;   
          fp = fopen("myfile.c", "r");     
          while((ch=getc(fp))!=EOF)  
          {      
              if(ch == '\n')             
                i++;  
           } 
           fclose(fp);  
           return 0; 
     } 
    

     

  2. A.

    The code counts number of characters in the file

    B.

    The code counts number of words in the file

    C.

    The code counts number of blank lines in the file

    D.

    The code counts number of lines in the file

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. Which of the following statement is correct about the program?

    #include 
    
     int main() 
     {  
        FILE *fp;  
        char str[11], ch;  
        int i=0;    
        fp = fopen("INPUT.TXT", "r");     
        while((ch=getc(fp))!=EOF) 
        {       
           if(ch == '\n' || ch == ')         
           {
             str[i]='\0';             
             strrev(str);             
             printf("%s", str);             
             i=0;     
          }     
          else        
             str[i++]=ch;    
         }     
         fclose(fp);   
          return 0;
      } 
    

  4. A.

    The code writes a text to a file

    B.

    The code reads a text files and display its content in reverse order

    C.

    The code writes a text to a file in reverse order

    D.

    None of above

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. Point out the correct statements about the program?

     #include 
     int main()
     {     FILE *fptr;   
           char str[80];  
           fptr = fopen("f1.dat", "w");     
           if(fptr == NULL)         
                printf("Cannot open file");  
          else   
          {         
              while(strlen(gets(str))>0)         
              {        
                 fputs(str, fptr);             
                 fputs("\n", fptr);         
             }   
             fclose(fptr); 
        }  
        return 0; 
    } 
    

  6. A.

    The code copies the content of one file to another

    B.

    The code writes strings that are read from the keyboard into a file.

    C.

    The code reads a file

    D.

    None of above

    View Answer

    Workspace

    Discuss Discuss in Forum