/Gnl

Get next line project of 42 school

Primary LanguageCMIT LicenseMIT

Status

Get_next_line

get_next_line is a 42 school project whose goal is to create a function that reads a line ending with a newline character from a file descriptor.

How to use

  • Clone the repository with git clone
  • Compile your program with get_next_line.c and get_next_line_utils.c
  • Include the header file get_next_line.h in your project

Mandatory part

  • The function must be named get_next_line.
  • The function must be prototyped as follows: int get_next_line(int fd, char **line);
  • The function must return its result without ’\n’.
  • The function must return 1 when it reads a line, 0 when it has finished reading and -1 when an error has occurred.
  • The function must be able to handle memory leaks.

Bonus part

  • Manage multiple file descriptors without losing the reading thread on each of the descriptors.

Example

cc name_file.c get_next_line.c get_next_line_utils.c -o name_program #the name_program executable
#include "get_next_line.h"

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

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

To do

  • Better error handling
  • Better Code