60 627
Assignments Done
97,8%
Successfully Done
In April 2018

Answer to Question #41451 in C++ for b.neha reddy

Question #41451
write a C program to create a file and to display the contents and delete the file
Expert's answer
#include <stdio.h>

int main() {
FILE *out = fopen("file.txt", "w+");
FILE *in = fopen("file.txt", "r");

int temp = 0;

for ( int i = 0; i < 15; i++ ) {
fprintf(out, "%d\n", i);// filliing the file with values as we have created it and it contains EOF only
}
for ( int j = 0; j < 15; j++ ) {
fscanf(in, "%d", temp);
printf("%d\n", temp);//showing the contents
}
if( remove( "file.txt" ) != 0 ) {
perror( "Error deleting file" );
} else {
puts( "File successfully deleted" );
}

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions