Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

SaraFreitas-dev/get_next_line

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

This project has been created as part of the 42 curriculum by sarfreit.

Description

The get_next_line project consists of implementing a function that reads and returns one line at a time from a file descriptor. Its goal is to allow efficient line-by-line reading while handling partial reads and preserving state between function calls.

โœ… Mandatory part

The project must:

  • Read text one line per call
  • Use only the read() function for input
  • Store unfinished data in a static variable
  • Return NULL when nothing is left to read
  • Handle arbitrarily long lines and any buffer size

๐Ÿงฉ Bonus part

Additionally, the bonus version must:

  • Support multiple file descriptors simultaneously
  • Keep a separate static buffer for each FD
  • Ensure the function remains independent across calls

Instructions

The project is written in C and must be compiled with a defined BUFFER_SIZE.

Define BUFFER_SIZE and compile the mandatory files

cc -Wall -Wextra -Werror -D BUFFER_SIZE=42 main_mandatory.c get_next_line.c get_next_line_utils.c -o test_mandatory

Execute the tester

./test_mandatory

Define BUFFER_SIZE and compile the bonus files

cc -Wall -Wextra -Werror -D BUFFER_SIZE=10 main_bonus.c get_next_line_bonus.c get_next_line_utils_bonus.c -o test_bonus

Execute the tester

./test_bonus

Check for Leaks

valgrind --leak-check=full --show-leak-kinds=all ./test_mandatory
valgrind --leak-check=full --show-leak-kinds=all ./test_bonus

Resources

For this project I used the help of some GitBooks from older students, and websites like GeeksforGeeks and W3Schools.

About

๐Ÿ”Ž 42 School project implementing a function that reads and returns one line at a time from a file descriptor.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.