Skip to content

Development repository for the 42cursus' get_next_line project

Notifications You must be signed in to change notification settings

ricky9leet/1337_get_next_line

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🚀 1337 Project: get_next_line

Development repository for the 42cursus' get_next_line project
For more about 1337 Coding School and its projects, feel free to connect with me on LinkedIn.


🏆 Project Score: 112/100 🎉

I successfully completed the get_next_line project, including the bonus part handling multiple file descriptors, with an exceptional score! (The code I provided is fixed so the final grade for it would be 125/100).

📜 What is get_next_line?

The get_next_line function reads a file line by line, handling various file descriptors efficiently.

char *line;
while ((line = get_next_line(fd)))
{
    printf("%s", line);
    free(line);
}

🌟 Key Features:

  • Reads one line at a time (including \n)
  • Efficient buffer management
  • Handles multiple file descriptors (Bonus Part ✅)
  • Works on any file, including stdin

🏗️ How It Works

  1. Uses a static buffer to store leftover data between function calls.
  2. Reads the file chunk by chunk (defined by BUFFER_SIZE).
  3. Extracts and returns a single line on each call.
  4. Frees memory properly to prevent leaks.

🛠️ Core Functions:

Function Description
get_next_line(int fd) Reads and returns the next line from fd
ft_strjoin(s1, s2) Concatenates two strings
ft_strchr(s, c) Finds character c in string s
ft_strdup(s) Duplicates a string
ft_substr(s, start, len) Extracts a substring

🚀 Bonus Part: Handling Multiple File Descriptors

The bonus part extends get_next_line to handle multiple file descriptors simultaneously, ensuring:

  • Independent reading from different files
  • No data loss between function calls
  • Smooth performance in multi-file environments

🏗️ How to Use

This project includes a Makefile for easy compilation.

🔹 Compilation

Run the following command to compile:

make

This will generate get_next_line.a (static library).

🔹 Usage in Your Code

To use get_next_line, include the header and link the library:

#include "get_next_line.h"

Compile your program with:

gcc main.c get_next_line.a -o my_program

🔹 Cleaning

To remove object files and binaries:

make clean   # Removes object files
make fclean  # Removes object files and library
make re      # Cleans and recompiles everything

📌 Useful Links

📚 Documentation & References

🛠 Technical Articles & Discussions

Happy coding! 🚀

About

Development repository for the 42cursus' get_next_line project

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages