Question: C PROGRAM read and write files in C. Note that the default working directory in CLion is the cmake-build-debug directory. So, if you want to

C PROGRAM read and write files in C.

Note that the default working directory in CLion is the cmake-build-debug directory. So, if you want to create or read files, you will need to provide a path from that directory to the location of the file being read or the desired location of the file being written.

Creat a file called data.txt in the cmake-build-debug directory. Type some stuff in the file. It doesn't really matter what stuff.

Code should read all data from data.txt and write 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!