aabduvak / GNL

Get Next Line is an individual project at 42 that requires us to create a function similar to the getline from CPP and fgets from C. This function allows a file to be read line after line if called in a loop.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🧰 Get Next Line

FUNCTION TO GET LINE FROM FILE DESCRIPTOR

GitHub code size in bytes Number of lines of code Code language count GitHub top language GitHub last commit


💡 About the project

_The goal of this project is to create the function get_next_line.c which, when called in a loop, will then allow the available text in the file descriptor to be read one line at a time until the end of the file. The program must compile with the flag-D BUFFER_SIZE=xx which will be used as the buffer size for the read calls in get_next_line.

What is GNL?

Get Next Line is an individual project at 42 that requires us to create a function similar to the getline from CPP and fgets from C. This function allows a file to be read line after line if called in a loop.

Application flow

Click here for the interactive link.

Objectives

  • Unix logic

Skills

  • Rigor
  • Unix
  • Algorithms & AI

My grade

Getting started

Follow the steps below

# Clone the project and access the folder
git clone https://github.com/abdulazizabduvakhobov/GNL && cd GNL/
# 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)
{
	char	*temp;
	int	fd;
	fd = open("myfile.txt", O_RDONLY);
	while(1)
	{
		temp = get_next_line(fd);
		if (!temp)
			break ;
		printf("%s", temp);
		free(temp);
	}
	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!

Functions table reference

The functions present in the utils are from the Libft with some code optimizations.

GNL Functions

Name Description
ft_clear_backup Free the memory and sets to NULL a pointer of type **char.
ft_update Joins all slices of backup and returns it
ft_init_string Creates new string and return the result string
get_next_line Reads a line from a file descriptor.

Libft Functions

Name Description
ft_strlen Computes the length of the string but not including the terminating null character.
ft_substr Creates new string from start parameter to length
ft_strchr Returns a substring from the string 's'. The substring begins at index 'start' and is of maximum size 'len'.
ft_strjoin Returns a new string, which is the result of the concatenation of 's1' and 's2'.

Updating

The project is regularly updated with bug fixes and code optimization.


📋 Testing

You can use any of this third party testers to test the project

About

Get Next Line is an individual project at 42 that requires us to create a function similar to the getline from CPP and fgets from C. This function allows a file to be read line after line if called in a loop.

License:GNU General Public License v3.0


Languages

Language:C 100.0%