An open API service indexing awesome lists of open source software.

https://github.com/khammerschmidt/42cursus-get_next_line

Reading one line from a file descriptor with a varying BUFFER_SIZE.
https://github.com/khammerschmidt/42cursus-get_next_line

static-variables

Last synced: 2 months ago
JSON representation

Reading one line from a file descriptor with a varying BUFFER_SIZE.

Awesome Lists containing this project

README

        




🧰 get_next_line


Reading a line from a file descriptor
Start date: 09/august/2021
Project status: completed 105/100 points


Github repo size
Number of lines in code
Languages used in repo
Top used progamming language

## 💡 About the project
> Write a project with maximum of 10 functions under the 42 norminette restrictions, that reads one line from a file descriptor with varying BUFFER_SIZE. Thereby, only one line should be returned and any remains after the newline should be saved for a repetitive function call.

**Requirements**
- Repeated calls (e.g., using a loop) to get_next_line() function should read the text file pointed to by the file descriptor, one line at a time.
- The function should return the line that was read. If there is nothing else to read or if an error occurred, it should return NULL.
- Function should work as expected both when reading a file and when reading from the standard input.
- The returned line should include the terminating \n character, except if the end of file was reached and does not end with a \n character.
- lseek() is forbidden.
- Global variables are forbidden.

**Key learning points**
- Learning about file descriptors and reading from a file
- Using static variables

## 🛠️ **Usage**

clone the repository:
```bash
git clone https://github.com/KHammerschmidt/42cursus-get_next_line &&
cd 42cursus-get_next_line &&
git clone https://github.com/KHammerschmidt/42cursus-Libft
```

to modify the buffer size used by read() adapt BUFFERSIZE value n in
[`Makefile`](./Makefile) ``` CPPFLAGS := -D BUFFER_SIZE=n ```

to compile the project:
```bash
make
```