This project has been created as part of the 42 curriculum by npillet.
The goal of this project is to create a function that reads a text file line by line, one line at a time, from a file descriptor. There's no size limit to the file length. In this project, the concept of static variables will be used.
The bonus consists of reading multiple file descriptors at the same time. For example, the code reads the first line from the first file, then moves to the first line from a second file and comes back to the first file to read the second line. It will continue that way without losing track to where it stops reading until all the files are done being read. All of that must be achieved using one static variable throughout the code.
A main file and a few text files will be provided during the evaluation process to test the code. To compile this code, this command must be used:
cc -Wall -Werror -Wextra <files>.cIt must also work with the following flag:
-D BUFFER_SIZE=42Here, 42 is a placeholder number that can be replaced by any positive number possible. For the execution of the program, once compiled, the following is typed on the terminal:
./a.outIf the program is compiled for a stdin usage, it will wait for an input. Once a key or multiple of them are pressed, the enter key should be pressed and the program will return that input. To kill the process, press ctrl + d at the same time.
For this project, I chose to approach the problem using strings. To do so, we will move BUFFER_SIZE characters in the text file to read and copy in a string until the code notices either a '\n' or '\0' which signifies a new line in the first case or the end of the file in the other.
For the bonus, I took the code I did for the mandatory part and modified only the static variable, making it a 2D array. That way, I could take care of the multiple file descriptors I could use to read multiple files simultaneously.