Skip to content

Repository files navigation

This project has been created as part of the 42 curriculum by ipinto-m.

GetNextLine


📝 Description

The get_next_line project consists of implementing a function in C that reads a file (or input) line by line.
Each call to the function returns the next line from the file until reaching the End Of File (EOF).

This project helps develop a deeper understanding of:

  • File descriptors and file handling
  • Dynamic memory allocation
  • Buffer management
  • Maintaining state between function calls

🚀 Instructions

Compilation

To compile the project:

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

You can change the value of BUFFER_SIZE as needed.

Usage

Basicc usage example:

#include "get_next_line.h"
#include <fcntl.h>
#include <stdio.h>

int main(void)
{
    int fd = open("file.txt", O_RDONLY);
    char *line;

    while ((line = get_next_line(fd)) != NULL)
    {
        printf("%s", line);
        free(line);
    }
    close(fd);
    return (0);
}

📚 Resources

References


Use of AI

For this project, Artificial Intelligence was used as an educational assistant for the following tasks:

  • Logic Clarification: Assisting in the understanding of file descriptors, static variables, and buffer management for line-by-line file reading.
  • Edge Case Identification: Generating test scenarios involving empty files, files without newline characters, multiple file descriptors, and varying BUFFER_SIZE values.
  • Memory Management Guidance: Helping clarify proper allocation and deallocation strategies to avoid memory leaks.
  • Documentation Formatting: Structuring and proofreading this README.md file to ensure it meets project requirements and professional standards.
  • Note: All project code was implemented manually. AI was used exclusively to clarify concepts and assist with documentation, ensuring the learning process remained central to the project.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages