Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C Open file.c. Extend it so it reads all data from data.txt and writes this data to a new file. The name of the

in C

Open file.c. Extend it so it reads all data from data.txt and writes this data to a new file. The name of the new file should be requested from the user.

Note that because the default working directory is cmake-build-debug, the new generated file will be there as well unless a path elsewhere is specified. For example, if you want the new file to be in the src directory, you could take the user's entry of "data2.txt" and create a file ../src/data2.txt.

Data should be copied from data.txt into the new file (with the users provided name) one character at a time. All files should be closed before the program ends!

You may want to explore the manual pages for:

  • fgetc
  • fputc
  • fopen
  • fclose
  • fscanf

File.c

#include  int main(void) { /* file handles */ FILE *outputFile=NULL; /* open files for writing*/ outputFile = fopen("cwork.dat", "w"); if(outputFile == NULL) return(1); /* need to do explicit ERROR CHECKING */ /* write some data into the file */ fprintf(outputFile, "Hello there"); /* dont forget to close file handles */ fclose(outputFile); return 0; }

data.txt

There are no mistakes here, only happy accidents.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

how would you have done things differently?

Answered: 1 week ago