C Programming - Input / Output - Discussion

Discussion Forum : Input / Output - Point Out Correct Statements (Q.No. 2)
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;
}
The code writes a text to a file
The code reads a text files and display its content in reverse order
The code writes a text to a file in reverse order
None of above
Answer: Option
Explanation:

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

Discussion:
2 comments Page 1 of 1.

Kamalpreet singh said:   3 years ago
I totally agree @StevenAlexander.

The answer should be [D].

Steven ALexander said:   5 years ago
The program reads the INPUT.TXT file and reverses each section that ends in a newline or a space, but it drops the newlines and spaces.

The entire content is NOT printed in reverse order.

Post your comments here:

Your comments will be displayed after verification.