C Programming - Input / Output - Discussion

2. 

Which of the following statement is correct about the program?

#include<stdio.h>

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

[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

Answer: Option B

Explanation:

This program reads the file INPUT.TXT and store it in the string str after reversing the string using strrev function.


Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.