Get Next Line delivers a function, get_next_line()
, that retrieves a line from a file descriptor. It’s divided into two parts:
- Mandatory Part: A single function to read lines sequentially from a file descriptor or standard input.
- Bonus Part: Enhanced version supporting multiple file descriptors simultaneously with a single static variable.
- Returns a line ending with
\n
(unless EOF is reached without it). - Handles both file input and standard input efficiently.
- Uses static variables for state persistence across calls.
- Bonus: manages multiple file descriptors without mixing their reading threads.
- Written in C, adhering to the 42 Norm.
- No unexpected crashes (e.g., segmentation faults).
- No memory leaks from heap allocations.
- Compiled with
-Wall -Wextra -Werror
and-D BUFFER_SIZE=n
(e.g., 42). - No use of
libft
,lseek()
, or global variables.
- C compiler (e.g.,
clang
orgcc
). make
utility.
-
Clone the repository:
git clone https://github.com/msabr/GET_NEXT_LINE_1337 cd GET_NEXT_LINE_1337
-
Build the mandatory part:
cc -Wall -Wextra -Werror -D BUFFER_SIZE=42 get_next_line.c get_next_line_utils.c
-
Build the bonus part (optional, separately):
cc -Wall -Wextra -Werror -D BUFFER_SIZE=42 get_next_line_bonus.c get_next_line_utils_bonus.c
-
Run with a file or standard input:
./a.out <file>
get_next_line.h
: function prototype for mandatory part.get_next_line.c
: main function source.get_next_line_utils.c
: helper functions.get_next_line_bonus.h
: bonus function prototype.get_next_line_bonus.c
: bonus main source.get_next_line_utils_bonus.c
: bonus helper functions.