C Programming - Input / Output - Discussion
Discussion Forum : Input / Output - Point Out Correct Statements (Q.No. 3)
3.
Point out the correct statements about the program?
#include<stdio.h>
int main()
{
FILE *fptr;
char str[80];
fptr = fopen("f1.dat", "w");
if(fptr == NULL)
printf("Cannot open file");
else
{
while(strlen(gets(str))>0)
{
fputs(str, fptr);
fputs("\n", fptr);
}
fclose(fptr);
}
return 0;
}
Answer: Option
Explanation:
This program get the input string from the user through gets function and store it in the file f1.txt using fputs function.
Discussion:
3 comments Page 1 of 1.
Piyush Agarwal said:
1 decade ago
Without <string. H> how is this program even working?
Shivani said:
4 years ago
Shouldn't this run for infinite time because of the while loop? Please, anyone, tell me.
Pawan Kumar Singh said:
2 years ago
But without string.h how it possible sir?
It shows an error, right?
It shows an error, right?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers