{"id":18983182,"url":"https://github.com/marcusvinix/get_next_line","last_synced_at":"2025-06-24T06:33:37.970Z","repository":{"id":110128418,"uuid":"373533902","full_name":"MarcusVinix/get_next_line","owner":"MarcusVinix","description":"This is a project of 42 São Paulo.  In this project I'll write a function which returns a line read from a file descriptor, without the  newline.  ","archived":false,"fork":false,"pushed_at":"2021-06-15T21:02:22.000Z","size":161,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-01T12:12:12.277Z","etag":null,"topics":["42","42school","c","gnl42"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarcusVinix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-03T14:21:17.000Z","updated_at":"2023-04-07T14:26:00.000Z","dependencies_parsed_at":"2023-03-13T13:58:34.283Z","dependency_job_id":null,"html_url":"https://github.com/MarcusVinix/get_next_line","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcusVinix%2Fget_next_line","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcusVinix%2Fget_next_line/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcusVinix%2Fget_next_line/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcusVinix%2Fget_next_line/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarcusVinix","download_url":"https://codeload.github.com/MarcusVinix/get_next_line/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239987534,"owners_count":19729824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["42","42school","c","gnl42"],"created_at":"2024-11-08T16:16:12.351Z","updated_at":"2025-02-21T09:27:00.912Z","avatar_url":"https://github.com/MarcusVinix.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Get Next Line\r\n\r\n\u003e This is the function get_next_line, which will return a line from a file descriptor passed, this is my second project as a cadet at School 42 São Paulo.\r\n\r\n## Description\r\n\r\n\u003e The aim of this project is to make you code a function that returns a line ending with a newline, read from a file descriptor.  \r\n\r\n\u003e Calling the function get_next_line in a loop will then allow you to read the text available on a file descriptor one line at a time until the EOF.\r\n\r\n\u003eThe return of this function is:\r\n\u003e * 1 if found a line with \\n on the end;\r\n\u003e * 0 if found the last line of the file;\r\n\u003e * -1 if a error is found\r\n\r\n### How use the function \r\n\r\n```c\r\n#include \"get_next_line.h\"\r\n#include \u003cstdio.h\u003e\r\n#include \u003cfcntl.h\u003e\r\n#include \u003cstdlib.h\u003e\r\n\r\nint\tmain(void)\r\n{\r\n\tint\t\tfd;\r\n\tint\t\tgnl;\r\n\tchar\t*line;\r\n\r\n\tfd = open(\"file\", O_RDONLY);\r\n\tgnl = get_next_line(fd, \u0026line);\r\n\twhile(gnl)\r\n\t{\r\n\t\tprintf(\"%s\\n\", line);\r\n\t\tfree(line);\r\n\t\tgnl = get_next_line(fd, \u0026line);\r\n\t}\r\n\tfree(line);\r\n\tclose(fd);\r\n\treturn (0);\r\n}\r\n```\r\n\u003e The function gnl make the allocation of memory for the variable line.  \r\n\u003e So its necessary call free after use the variable for avoid problems with leak.  \r\n\u003e This function has an undefined behavior if, between two calls, the same file descriptor switches to a different file before the EOF has been reached on the first fd.\r\n\r\n\u003e If you need read multiple files without reached the EOF, use the function bonus.  \r\n\u003e Its necessary just change the include of header used by `get_next_line_bonus.h`\r\n\r\n```c\r\n#include \"get_next_line_bonus.h\"\r\n#include \u003cstdio.h\u003e\r\n#include \u003cfcntl.h\u003e\r\n#include \u003cstdlib.h\u003e\r\n\r\nint\tmain(void)\r\n{\r\n\tint\t\tfd;\r\n\tint\t\tfd2;\r\n\tint\t\tfd3;\r\n\tchar\t*line;\r\n\r\n\tfd = open(\"file\", O_RDONLY);\r\n\tfd2 = open(\"file3\", O_RDONLY);\r\n\tfd3 = open(\"file3\", O_RDONLY);\r\n\tget_next_line(fd, \u0026line);\r\n\tprintf(\"%s\\n\", line);\r\n\tfree(line);\r\n\tget_next_line(fd2, \u0026line);\r\n\tprintf(\"%s\\n\", line);\r\n\tfree(line);\r\n\tget_next_line(fd3, \u0026line);\r\n\tprintf(\"%s\\n\", line);\r\n\tfree(line);\r\n\tclose(fd);\r\n\tclose(fd2);\r\n\tclose(fd2);\r\n\treturn (0);\r\n}\r\n```\r\n\r\n### How Compile\r\n\r\n\u003e Compilation will be done this way :  \r\n\u003e `gcc -Wall -Wextra -Werror -D BUFFER_SIZE=32\r\nget_next_line.c get_next_line_utils.c`  \r\n\u003e You can choose any length of BUFFER_SIZE.  \r\n\u003e If you want use the bonus part to be able to use multiple files descriptor, you just need add `_bonus` at the end of the name, `get_next_line_bonus.c`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcusvinix%2Fget_next_line","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcusvinix%2Fget_next_line","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcusvinix%2Fget_next_line/lists"}