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;
}
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.
Steven ALexander said:
7 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.
The entire content is NOT printed in reverse order.
Kamalpreet singh said:
5 years ago
I totally agree @StevenAlexander.
The answer should be [D].
The answer should be [D].
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers