Skip to content

Ce projet a pour but de vous faire développer une fonction qui renvoie une ligne lue depuis un descripteur de fichier.

Notifications You must be signed in to change notification settings

riceset/get_next_line

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Get Next Line

Summary

The 42 school's get_next_line project is where we learn to read from a file descriptor, as well as the use of static variables. This function returns a single line from a given file descriptor. If called in a loop, get_next_line returns the entire contents of a file, line by line until it reaches the end of the file. It can be compiled specifying any buffer size.

Getting started

First, clone this repository and cd into it:

$ git clone https://github.com/riceset/get_next_line; cd get_next_line

Compile the executable file with:

$ make

Or use the following command to compile it with the bonus files:

$ make bonus

Usage

This function is not a stand-alone program, its files must be included and compiled within another project.

Example main.c:

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

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

	(void)argc;
	fd = open(argv[1], O_RDONLY);
	line = "";
	while (line != NULL)
	{
		line = get_next_line(fd);
		printf("%s", line);
	}
	fd = close(fd);
	return (0);
}

Compilation:

$ gcc main.c get_next_line.c get_next_line_utils.c

BUFFER_SIZE can be specified at compilation to override the default BUFFER_SIZE:

$ gcc -D BUFFER_SIZE=42 main.c get_next_line.c get_next_line_utils.c

Execution:

$ ./a.out [file]

Output should show the entire contents of the given file.

Execution with stdin:

$ ./a.out /dev/tty

Program will wait for input, then once the enter key is pressed, print out the input as well as get_next_line's output. The process can be killed with ctrl-c.

About

Ce projet a pour but de vous faire développer une fonction qui renvoie une ligne lue depuis un descripteur de fichier.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published