ricardoreves / 42-get-next-line

➡️ May it be a file, stdin, or even later a network connection, you will always need a way to read content line by line. It is time to start working on this function, which will be essential for your future projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

42 Get Next Line

Language Licence Score norminette

🪧 Overview

Description

May it be a file, stdin, or even later a network connection, you will always need a way to read content line by line. It is time to start working on this function, which will be essential for your future projects.

Goal

This project will not only allow you to add a very convenient function to your collection, but it will also make you learn a highly interesting new concept in C programming: static variables.

📷 Preview

[line:01]                                          
[line:02]                                          
[line:03]                                          
[line:04]               @@@@@@@*   ,@@@@@@ @@@@@@@ 
[line:05]             @@@@@@@      ,@@@    @@@@@@@ 
[line:06]          &@@@@@@#        ,@      @@@@@@@ 
[line:07]        @@@@@@@                 ,@@@@@@@  
[line:08]     %@@@@@@%                 @@@@@@@.    
[line:09]   @@@@@@@                  @@@@@@@       
[line:10]  @@@@@@@@@@@@@@@@@@@@@,  ,@@@@@@@      @ 
[line:11]  @@@@@@@@@@@@@@@@@@@@@,  ,@@@@@@@   @@@@ 
[line:12]                @@@@@@@,  ,@@@@@@@ @@@@@@ 
[line:13]                @@@@@@@,                  
[line:14]                @@@@@@@,                  
[line:15]                                          
[line:16]                                          
[line:17]                                          

🚀 Getting Started

Installation

  1. Clone the project.
git clone git@github.com:ricardoreves/42-get-next-line.git
  1. Navigate to the project directory.
cd 42-get-next-line

🕹 Usage

  1. implementation of get_next_line() function
#include "get_next_line.h"

int	main(int argc, char **argv)
{
	int		i;
	int		fd;
	char	*line;

	if (argc != 2)
		printf("Error: a file path is required\n");
	else
	{
		i = 0;
		fd = open(argv[1], O_RDONLY);
		while (++i)
		{
			line = get_next_line(fd);
			if (!line)
				break ;
			printf("[line:%.2d]%s", i, line);
			free(line);
		}
		close(fd);
	}
	return (0);
}
  1. Compile program and create executable
gcc -Wall -Werror -Wextra main.c get_next_line.c get_next_line_utils.c -D BUFFER_SIZE=42 -o prog
  1. Run program with a file path
./prog file-to-read.txt

📚 References

🧰 Tools

  • github.com - gnlTester (2019+). Tester for the get next line project of 42 school (with personalized leaks checking on mac, using valgrind on linux)

📝 License

Distributed under the MIT License. See LICENSE for more information.

About

➡️ May it be a file, stdin, or even later a network connection, you will always need a way to read content line by line. It is time to start working on this function, which will be essential for your future projects.

License:MIT License


Languages

Language:C 78.8%Language:Makefile 21.2%