Skip to content
/ 42GNL Public

The aim of this project is to code a function that returns a line ending with a newline, read from a file descriptor.

Notifications You must be signed in to change notification settings

lilangbr/42GNL

Repository files navigation

Get_next_line42

🔧 C, Makefile
🌍 MacOs

This is a reinterpretation of the fgets() function. Its purpose is to code a function that opens a file, reads a predetermined number (buffer) of characters, and returns the text in the standard output, read from a file descriptor, separated by line breaks. It works with concepts such as the use of data buffers, static variables, file descriptors, as well as double pointer with different use of arrays.

Use:

🚧 project:

42Libft $ make

🚿 Clean Obj files:

42Libft $ make clean

🚿 🚿 Clean All (obj files + binary):

42Libft $ make fclean

🚿 🚿 🚧 Clean All + build:

42Libft $ make re


See Makefile

Main Idea

Here, a simple drawning about the main idea: copy buffer until find a '\n', keeping the residual for the next call.

gnl_idea

Logic

Below, a get_next_line's flowchart - Before final version: (Note: This diagram is not complete. After reading the file, there is no residue, that is, when EOF is reached, the buffer is still checked by repeating the buffer breaking process if there is '/ n'. This diagram served more for an initial understanding. The final version, below in this document, is more detailed and assertive.)

gnl_flowchart

GNL Vars

The get_next_line's variables. Note that the bonus part (The part that treats with various files at same time), uses an string''s array, like shows the figure below, called by residual[fd]. Where each position referes to particular FD. On the simple get_next_line, the mandatory part, this is a simple string var.(residual).

Var list:

  • buff: Read buffer (used on read function, to keep the read part)
  • residual: residue buffer (has the same size of buff, and keep the residue of buff, after the buff is append on the line)
  • oneline: Flag that indicates that function reach a line

(Note: As the buffer variable is only used within gnl_core, I chose to use a simple pointer, that is, I don't need its reference outside the scope of this function. So, the correct thing in this diagram is just buf and * buf. Like the diagram above, this was only used to understand the data structure.)

gnl_vars

FINAL VERSION

To according with moulinette, i had to split my function, because it had more than 70 lines. So, i've created a "gnl_core", that resumes the main logic of the code. Some functions, had your names changed to seem more useful to understanding.

gnl_new_flowchart gnl_new_flowchart_labels

testers

42TESTERS-GNL

42cursus_gnl_tests

GNL_Lover

Get_Next_Line_Tester

gnl_tester

About

The aim of this project is to code a function that returns a line ending with a newline, read from a file descriptor.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages