Input / Output

Q1:
Which of the following statement is correct about the program?
#include<stdio.h>

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;
}

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

ANS:A - The code counts number of characters in the file

This program counts the number of lines in the file myfile.c by counting the character '\n' in that file.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.