Examveda

How are many number of characters available in newname.txt?
#include <stdio.h>
int main ()
{
    FILE * p;
    int n = 0;
    p = fopen ("newname.txt", "rb");
    if (p == NULL) 
        perror ("Error opening file");
    else
    {
        while (fgetc(p) != EOF)
        {
            ++n;
        }
        if (feof(p)) 
        {
            printf ("%d\n", n);
        }
        else
            puts ("End-of-File was not reached.");
        fclose (p);
    }
    return 0;
}

A. 10

B. 15

C. Depends on the text file

D. 34

Answer: Option C


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it