https://github.com/link-wolf/get_next_line
42 project - C-funtion to return the next line from a file descriptor
https://github.com/link-wolf/get_next_line
42 42born2code 42school c macos
Last synced: 2 months ago
JSON representation
42 project - C-funtion to return the next line from a file descriptor
- Host: GitHub
- URL: https://github.com/link-wolf/get_next_line
- Owner: Link-Wolf
- Created: 2022-02-24T09:59:17.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-01T13:30:02.000Z (almost 2 years ago)
- Last Synced: 2025-05-26T21:05:22.611Z (about 1 year ago)
- Topics: 42, 42born2code, 42school, c, macos
- Language: C
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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
## About The Project
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](https://github.com/Link-Wolf/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
## 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
```sh
git clone https://github.com/Link-Wolf/get_next_line.git
```
2. Include get_next_line in your C project
```c
#include "get_next_line/get_next_line_bonus.h"
```
3. Compile your project with the get_next_line sources
```sh
gcc [your_project.c] get_next_line_bonus.c get_next_line_utils_bonus.c -D BUFFER_SIZE=
```
## Usage
Use the get_next_line function to read any file line by line !
```c
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$
```
## Roadmap
- [x] Add bonus features
See the [open issues](https://github.com/Link-Wolf/get_next_line/issues) for a full list of proposed features (and known issues).
## 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