Skip to content

Latest commit

 

History

History
129 lines (92 loc) · 4.38 KB

README.md

File metadata and controls

129 lines (92 loc) · 4.38 KB

42 Logo

Get_next_line

A custom project from 42 School for efficient file reading

Get_next_line Badge

GitHub code size in bytes Code language count GitHub top language GitHub last commit


✨ Overview

Get_next_line is an individual project at 42 School that implements a function to read a file, returning one line at a time from a file descriptor. This project challenges your ability to manage memory, handle buffers, and work with file descriptors efficiently. The bonus part extends the functionality by allowing multiple file descriptors to be read concurrently.

The goal? Deliver a robust and efficient function that behaves similarly to the standard I/O functions while adhering to the 42 School coding standards.


📑 Key Features

Core Functionality

  • Line-by-Line Reading
    Reads one line at a time from a given file descriptor.

  • Buffer Management
    Efficiently handles input buffering to optimize read operations.

  • Memory Handling
    Dynamically allocates memory to store lines and avoids memory leaks.

Bonus Features

  • Multi-file Descriptor Support
    Capable of handling multiple file descriptors concurrently, ensuring that each file maintains its own reading state.

  • Linked List Implementation
    Bonus implementation leverages linked lists to dynamically manage multiple buffers and file descriptors.

Core Files


🛠️ Technologies Used

  • C — Core programming language.
  • Makefile — Build automation tool.

🚀 How to Build and Run

  1. Clone repository

    git clone git@github.com:doooriian/Get_next_line.git
  2. To use the library in your code, #include the following header

    #include "get_next_line.h"

  1. Follow these instructions
## Build and Run

Since the project contains only a function, you can test it by creating a simple `main.c` file that calls `get_next_line`
For example, here’s a minimal test program:

```c
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include "get_next_line.h"

int main(void)
{
    int fd = open("file.txt", O_RDONLY);
    if (fd < 0)
    {
        perror("Error opening file");
        return (1);
    }

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

    close(fd);
    return (0);
}

🧪 Testing

This project was tested using custom test cases to ensure robust performance and efficient memory management. The bonus functionality was extensively validated to handle multiple file descriptors simultaneously, using linked lists to manage dynamic buffers.

✅ Results

Here’s my score for the Get_next_line project:

Get_next_line Grade

📬 Contact

Feel free to reach out or contribute to this project via GitHub!