Skip to content

get_next_line a 42 curriculum project, you need to create a function that reads a line from a file descriptor.

Notifications You must be signed in to change notification settings

whoismtrx/42_get_next_line

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

Get_next_line

Overview

The aim of this project is to make you code a function like getline() in C. but with some diferences. The prject is a part of the 42 curriculum, written in C language.

Key Features

The project contains 2 parts: Manadatory and Bonus.

  • Mandatory part is to code a function that returns a line ending with a newline, read from a file descriptor. and sould be able to memorize the reading position to read from the same file descriptor on the next call.
  • Bonus part is to code a function that can read from multiple file descriptors without losing the reading position.

Getting Started

to compile the project you need to clone the repository first, to that run the following command:

git clone https://github.com/whoismtrx/42_get_next_line.git get_next_line
cd get_next_line/src
cc -Wall -Wextra -Werror -D BUFFER_SIZE=1337 get_next_line.c get_next_line_utils.c main.c

Usage

to use the function you need to include the header file in your project and call the get_next_line function with the file descriptor you want to read from.

// example.c
#include "get_next_line.h"
char *line = get_next_line(fd);

Implementation

The function is implemented using a static variable to store the reading position and a buffer to store the read data. the function reads the data from the file descriptor and stores it in the buffer, then it searches for a newline character in the buffer, if it finds one it returns the line ending with the newline character, if not it reads more data from the file descriptor and appends it to the buffer and repeats the process. if the function reaches the end of the file it returns the last line without a newline character. lastly, the function frees the buffer and returns the line. this process is repeated on every call to the function.

Resources

Releases

No releases published

Packages

No packages published

Languages