Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cypri1-dev/42_get_next_line
This project is part of the curriculum at Ecole 42. The goal of "42_get_next_line" is to create a function that reads a line from a file descriptor.
https://github.com/cypri1-dev/42_get_next_line
bonus get-next-line get-next-line-42 getnextline getnextline-42 getnextline42 mandatory
Last synced: 28 days ago
JSON representation
This project is part of the curriculum at Ecole 42. The goal of "42_get_next_line" is to create a function that reads a line from a file descriptor.
- Host: GitHub
- URL: https://github.com/cypri1-dev/42_get_next_line
- Owner: cypri1-dev
- Created: 2024-01-23T16:12:01.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-04-10T23:12:18.000Z (9 months ago)
- Last Synced: 2024-04-11T02:05:45.421Z (9 months ago)
- Topics: bonus, get-next-line, get-next-line-42, getnextline, getnextline-42, getnextline42, mandatory
- Language: C
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
##
## Description
This project is part of the curriculum at Ecole 42. The goal of "42_get_next_line" is to create a function that reads a line from a file descriptor.The `get_next_line` function reads a line from a file descriptor. A "line" is defined as a succession of characters that end with a newline ('\n') or EOF (End of File) from the input file.
The function allocates memory for the line read, which must be freed by the caller when it is no longer needed. It returns 1 if a line has been read, 0 if the reading is complete, and -1 in case of an error.
## Usage
1. Install.
```bash
git clone https://github.com/cypri1-dev/42_get_next_line.git
cd 42_get_next_line
```
2. To use the `get_next_line` function, include the header file `get_next_line.h` in your project. Then, call the function with the file descriptor from which you want to read a line.## Example Usage
```c
#include "get_next_line.h"int main(void)
{
char *line;
int fd;
int ret;fd = open("example.txt", O_RDONLY);
if (fd == -1)
return (1);
while ((ret = get_next_line(fd, &line)) > 0)
{
printf("%s\n", line);
free(line);
}
if (ret == -1)
return (1);
close(fd);
return (0);
}
```