Given an initialized variable fileName , write a sequence of statements that cre
ID: 3845297 • Letter: G
Question
Given an initialized variable fileName, write a sequence of statements that create a file whose name is given by the variable and whose content is a single line consisting of "This Is File: " followed by the name of the file. Make sure that the data written to the file has been flushed from its buffer and that any system resources used during the course of running these statements have been released. (Do not concern yourself with any possible exceptions here-- assume they are handled elsewhere.)
Explanation / Answer
Code:
. #include <stdio.h>
#include<conio.h>
int main (void)
{
FILE *fptr;
char filename[] = "file.txt";
if((fptr = fopen(filename, "r")) == NULL)
{
printf("Cannot open %s. ", filename);
}
else
{
printf("Opening the %s file successfully ", filename);
printf("The value of fptr: ", fptr);
printf(" ....file processing should be done here.... ");
printf(" Ready to close the %s file. ", filename); .
if(fclose(fptr)==0)
printf("Closing the %s file successfully ", filename);
}
return ;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.