GITHUB BLOG
Ecole42 Get Next Line
bruno-valerohá cerca de 2 mesesmain
get_next_line
This project is part of the 42 curriculum and aims to create a function that returns, on each call, one line read from a file descriptor. It is an excellent opportunity to practice controlled file reading, the use of buffers, and static variables in C.
📚 Objective
Implement the function get_next_line()
capable of returning the next available line from a file descriptor, correctly preserving the state between successive calls. The return must include the newline character \n
, except at the end of the file.
🚫 Restrictions
- Use of
libft
is forbidden. No external custom functions may be used. - Only the functions
read
,malloc
, andfree
are allowed. - Global variables are prohibited.
lseek()
is forbidden.
✅ Mandatory Part
The function must have the following prototype:
- Must work with any valid file descriptor.
- Must read and return one line per call.
- Must return
NULL
in case of error or end of file. - The project must be compilable with:
🔁 Bonus Part
The bonus version of the project was successfully implemented and includes:
- Support for multiple file descriptors simultaneously.
- Use of only one static variable per call.
- Modular structure, with the following additional files:
To compile the bonus:
🧪 Usage Example
📝 Considerations
- The project was implemented with a focus on performance and readability.
- Memory management was carefully handled to avoid leaks and undefined behavior.
- Tested with different
BUFFER_SIZE
values, including1
,42
,9999
, and1000000
.
✅ Status
- Mandatory part completed
- Bonus part completed
- Validation with multiple file descriptors
- Validation with standard input (stdin)