Skip to content

Yassine-bayed/GetNextLine

Repository files navigation

Get Next Line | 42 Project

Brief :

                The get_next_line() is a function that reads lines with a newline character ('\n') from a file descriptor and returns the read line as a string.

  • The function takes a single parameter, an integer file descriptor fd which represents the file or stream to be read.
    It should work as expected both when reading from a file and when reading from the standard input.

  • The function should store the characters in a buffer:

    • When a newline character is encountered, the buffer is null-terminated and returned.
    • If the end of file is encountered and the last line does not have a newline character, the buffer should be returned without the null terminator.
  • The function should return the following:

    • A pointer to the read line, including the terminating newline character, if the read was successful.
    • NULL if there is nothing else to read, or an error occurred.

:fishsticks: Mandatory Part:

  • Prototype :

    char *get_next_line(int fd)

  • Header File ( get_next_line.h ) : must at least contain the prototype of the get_next_line() function.

  • Files :

    • Main File ( get_next_line.c ):
    • Header File ( get_next_line.h ) : must at least contain the prototype of the get_next_line() function.
    • Additional functions : need to be in the get_next_line_utils.c file.
  • External functs : read, malloc, free.

    • The buffer size for read() can be defined by the macro -D BUFFER_SIZE=n eg: gcc -Wall -Wextra -Werror -D BUFFER_SIZE=42 <files>.cin the compilation, but you need to choose a Default Value Of Your Choice. The code should be able to compile with or without the flag.
              💡 : Does your function still work if the BUFFER_SIZE value is 9999? If it is 1? 10000000? Do you know why?
    • Function should be memory leak free.
  • Forbidden :

    • You are not allowed to use your libft in this project.
    • lseek() is forbidden.
    • Global variables are forbidden.

    ℹ️ : Try to read as little as possible each time get_next_line() is called. If you encounter a new line, you have to return the current line. Don’t read the whole file and then process each line

💠 Bonus Part:

  • suffix the bonus part files using *_bonus.[c/h] :

    • get_next_line_bonus.c : Main File.
    • get_next_line_bonus.h : Header File.
    • get_next_line_utils_bonus.c : Additional functions.
  • Manage Multiple File Descriptors at The Same Time :

    For example :if you can read from the file descriptors 3, 4 and 5, you should be able to read from a different fd per call without losing the reading thread of each file descriptor or returning a line from another fd .

    It means that you should be able to call get_next_line() to read from fd 3, then fd 4, then 5, then once again 3, once again 4, and so forth.

          N.B :Both the buffer size and the line size can be of very different values. A file descriptor does not only point to regular files. Be smart and cross-check with your peers. Prepare a full set of diverse tests for defense.

ℹ️ When writing your tests, remember that:

  • Both the buffer size and the line size can be of very different values.
  • A file descriptor does not only point to regular files. Be smart and cross-check with your peers. Prepare a full set of diverse tests for defense. Once passed, do not hesitate to add your

📚 RESSOURCES:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages