This project involves creating a function that reads and returns a line from a file descriptor. It introduces an important concept in C programming: static variables.
- Reads a line from a file descriptor, returning it as a string.
- Works for both files and standard input.
- Returns
NULLwhen there is nothing left to read or when an error occurs. - Must include the newline character (
\n) except when EOF is reached.
- Function Name:
get_next_line. - Prototype:
char *get_next_line(int fd);. - Allowed external functions:
read,malloc, andfree. - No use of global variables.
- Must compile with
-D BUFFER_SIZE=n. - Code should be norm-compliant and not cause memory leaks.
- Implement
get_next_lineto manage multiple file descriptors simultaneously. - Use only one static variable.
- Submit additional files with
_bonussuffix:get_next_line_bonus.cget_next_line_bonus.hget_next_line_utils_bonus.c.
Compile with:
cc -Wall -Wextra -Werror -D BUFFER_SIZE=42 get_next_line.c get_next_line_utils.c -o gnlRun with:
./gnl <filename>- Submit the following files:
get_next_line.cget_next_line_utils.cget_next_line.h- (Bonus)
get_next_line_bonus.c,get_next_line_utils_bonus.c,get_next_line_bonus.h.
- Make sure all required rules are in
Makefile.
- Ensure the function works with different buffer sizes (1, 9999, etc.).
lseek()andlibftusage is forbidden.