Skip to content

Get Next Line is a project at 42. 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.

Notifications You must be signed in to change notification settings

Ra-Wo/Get-next-line

Repository files navigation

Get next line

Function to read line by line from file. 2021-2022

Declaration

char	*get_next_line(int fd);

Getting started

Follow the steps below

# Clone the project and access the folder
git clone https://github.com/Ra-Wo/Get-next-line.git && cd Get_next_line

# Create a main file
touch main.c
/*
** Example of a main, change "myfile.txt"
** to a file you want to read
*/

#include <stdio.h>
#include <fcntl.h>
#include "get_next_line.h"

int main(void)
{
	int	fd;

	fd = open("myfile.txt", O_RDONLY);

	while (1)
  	{
    		printf("%s", get_next_line(fd));
  	}
	return (0);
}
# Compile the files, example:
gcc get_next_line.c get_next_line.h get_next_line_utils.c main.c

# Execute your program
./a.out

# Well done!

About

Get Next Line is a project at 42. 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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages