Skip to content

Latest commit

 

History

History
39 lines (22 loc) · 1.57 KB

README.md

File metadata and controls

39 lines (22 loc) · 1.57 KB

get_next_line - @42Wolfsburg

description

get_next_line is a project about creating a function that reads a line ending with a newline character ('\n') from a file descriptor, without knowing its size beforehand.

main concepts in this project are:

→ static variables, and complexity of using of one or many of them;

→ allocations, in stack memory or in the heap memory;

→ manipulation and the life cycle of a buffer.

here are some resources i used:

handling a file by its descriptor in c

local, global and static variables in c

get_next_line explained : develop a function that reads a file line by line

42 get next line guide (string approach)

how does it work

this project uses special variables called static variables, they remember their value even after the function is called again.

my code reads lines from a file one by one, as required.

it first reads characters from the file until it encounters a newline character or reaches the end of the file.

then, it extracts the line it has read and returns it. the function keeps track of the remaining part of the line for future reads.

if there are no more lines to read, it returns NULL.

my final grade

get_next_line grade