FS-5: Manual append
Your task is to write a program on C/C++ that writes two lines in the files "first line" and "second line".
Description
Your task is to write a program on C/C++ that writes two lines in the files "first line" and "second line". Writing should happen into two different file descriptors but write into the same file.
Requirements
- Write a C/C++ program that gets the filepath with the first argument and opens it.
- File should not be opened with the O_APPEND file.
- You are not allowed to use seek/lseek to move the cursor to the end.
- The program writes two lines: "first line" and "second line". Each line is written in a different descriptor.
- After write, the file should contain both lines in the same file.
Hint: you may use dup/dup2.
Expected result
The resulting application should be able to build and execute from command line as follows:
make
./manual-append result.txtThe output file should contain the following text:
first line
second lineThe final solution should contain a Makefile for the multi-stage build. The Makefile should also contain targets all and clean. It's recommended to have compiler and compiler flags declared as Makefile variables. Alternatively, cmake could also be used instead of make.
FS-4: Redirect standard input
Redirect a program's standard input to read from a file instead of the keyboard, without changing its std::cin or scanf calls.
FS-10: Copy a file with holes
Copy a file in C++ on Linux while preserving its holes (sparse regions), overwriting the destination and reporting data and hole byte counts.