Skip to content

Link-Wolf/get_next_line

Repository files navigation

Link-Wolf - get_next_line 42 grade - 125 / 100 Year - 2022 stars - get_next_line forks - get_next_line issues - get_next_line OS - macOS

Logo

Get Next Line

Reading a line on a fd is way too tedious
A C function that returns a line ending with a newline, read from a file descriptor

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing

About The Project

get_next_line header

This project is focused on writing our own function to get a line from a file descriptor, without knowing its size beforehand

  • We must implement a buffer. We can't neither come back nor move in the file descriptor.
  • We can't use lseek, only read, malloc, free, nor the libft
  • We can't use globals variables nor FILE structure, but static variables are allowed
  • The buffer size used by read can be changed
  • Call the function in a loop will then allow to read the text available on a file descriptor one line at a time until the end of the text, no matter the size of either the text or one of its lines

There were also two additional bonus features

  • Be able to read multiple file descriptors at the same time
  • Only use one static variable

(back to top)

Getting Started

Because it's a simple C function, there isn't much to say here

Prerequisites

Having a C compiler like cc, gcc or clang

Installation

  1. Clone the repo
    git clone https://github.com/Link-Wolf/get_next_line.git
  2. Include get_next_line in your C project
    #include "get_next_line/get_next_line_bonus.h"
  3. Compile your project with the get_next_line sources
    gcc [your_project.c] get_next_line_bonus.c get_next_line_utils_bonus.c -D BUFFER_SIZE=<size>

(back to top)

Usage

Use the get_next_line function to read any file line by line !

int fd = open("my_awesome_file", 0);
char *line = get_next_line(fd);

while (line)
{
	printf("Next line : %s\n", line);
	line = get_next_line(fd);
}
printf("End of file\n");

Output (cat -e)

Next line : my_first_line$
Next line : my_second_line$
Next line : my_third_line$
Next line : my_fourth_line$
. . .
End of file$

(back to top)

Roadmap

  • Add bonus features

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

About

42 project - C-funtion to return the next line from a file descriptor

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages