Skip to content

This project is part of the curriculum at Ecole 42. The goal of "42_get_next_line" is to create a function that reads a line from a file descriptor.

Notifications You must be signed in to change notification settings

cypri1-dev/42_get_next_line

Repository files navigation

Description

This project is part of the curriculum at Ecole 42. The goal of "42_get_next_line" is to create a function that reads a line from a file descriptor.

The get_next_line function reads a line from a file descriptor. A "line" is defined as a succession of characters that end with a newline ('\n') or EOF (End of File) from the input file.

The function allocates memory for the line read, which must be freed by the caller when it is no longer needed. It returns 1 if a line has been read, 0 if the reading is complete, and -1 in case of an error.

Usage

  1. Install.
git clone https://github.com/cypri1-dev/42_get_next_line.git
cd 42_get_next_line
  1. To use the get_next_line function, include the header file get_next_line.h in your project. Then, call the function with the file descriptor from which you want to read a line.

Example Usage

#include "get_next_line.h"

int main(void)
{
    char *line;
    int fd;
    int ret;

    fd = open("example.txt", O_RDONLY);
    if (fd == -1)
        return (1);
    while ((ret = get_next_line(fd, &line)) > 0)
    {
        printf("%s\n", line);
        free(line);
    }
    if (ret == -1)
        return (1);
    close(fd);
    return (0);
}

About

This project is part of the curriculum at Ecole 42. The goal of "42_get_next_line" is to create a function that reads a line from a file descriptor.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages