Question
I have to write a C program that shall reverse a text file and store the reversed content into another file. Please, help with it.
I have to write a C program that shall reverse a text file and store the reversed content into another file. Please, help with it.
The names of the input and out files shall be given as the command line arguments. If the number of arguments is not three (including the program name) or any of the files cannot be opened, the program shall display an usage or error message, respectively, and terminate.
The program shall read the input file one line at a time and store it in a dynamically allocated buffer not longer than MAX_LINE_LENGTH bytes, where MAX_LINE_LENGTH shall be a macro. The remainder of the line that does not fit into the buffer shall be discarded, and a warning message shall be displayed.
The lines shall be stored in a dynamically and incrementally allocated array. The initial size of the array shall be INIT_NUMBER_OF_LINES, where INIT_NUMBER_OF_LINES shall be a macro. When the number of lines exceeds the array size, the array size shall be doubled.
The program shall write the lines of the original file in the reverse order, so that the last lines shall be written first, etc. Each line shall be written in the reversed order, too, so that the last character shall be written first, etc.
Before terminating, the program shall deallocate all memory fragments that have been previously allocated.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started