Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions