/get_next_line

Get Next Line is a project at 1337. It is a function that reads a file and allows you to read a line ending with a newline character from a file descriptor. When you call the function again on the same file, it grabs the next line. This project deals with memory allocation and when to free and allocate memory to prevent leaks. A (-1) is returned if an error occurred. A (0) is returned if the file is finished reading. And a (1) is returned if a line is read.

Primary LanguageC

Get_next_line 1337's PROJECT :


Reading a line on a fd is way too tedious

In this repo you will find all the codes developed during the get_next_line 1337's project, both mandatory's part and bonus part.


Mandatory

Calling the function get_next_line in a loop will then allow you to read the text available on the file descriptor one line at a time until the end of it. The function should return the line that has just been read. If there is nothing else to read or if an error has occurred it should return NULL.


Bonus

To succeed get_next_line with a single static variable. To be able to manage multiple file descriptors with your get_next_line. For example, if the file descriptors 3, 4 and 5 are accessible for reading, then you can call get_next_line once on 3, once on 4, once again on 3 then once on 5 etc. without losing the reading thread on each of the descriptors


The project

Header files :

Mandatory :

	MANDATORY ALGORITHM :

	GET_NEXT_LINE

	DESCRIPTION :
	Write a function which returns a line read from a
	file descriptor.

	RETURN VALUES :

	Read line: correct behavior.
	NULL: nothing else to read or an error occurred.

🔧 Nothing but libft functions !


ℹ️ This repository contains two versions of get_next_line, both works flawlessly.

Usage

Requirements

get_next_line requires gcc compiler and some standard libraries.

Instructions

Clone this repository in your local computer:

git clone https://github.com/ishakzail/get_next_line.git

To use the library in your code you will need to include the header:

#include "get_next_line.h"

or

#include "get_next_line_bonus.h"

To compile the program, use these flags:

Make sure to change the XX after BUFFER_SIZE to the buffer size you want the program to work with.

gcc -Wall -Wextra -Werror -D BUFFER_SIZE=XX get_next_line.c get_next_line_utils.c -I get_next_line.h