Question
#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;
}
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 B
Was this answer helpful ?
This program get the input string from the user through gets function and store it
in the file f1.txt using fputsfunction.
Was this answer helpful ?
Submit Solution