{"id":25764448,"url":"https://github.com/mewmewdevart/get_next_line","last_synced_at":"2026-05-14T23:42:42.561Z","repository":{"id":62285668,"uuid":"554965063","full_name":"mewmewdevart/get_next_line","owner":"mewmewdevart","description":"[42 Cursus]  Reading a line from a fd is way too tedious","archived":false,"fork":false,"pushed_at":"2022-11-21T18:25:09.000Z","size":119,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-03-10T13:06:30.655Z","etag":null,"topics":["42projects","c","file-descriptor","gnl","static-variables"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mewmewdevart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-20T18:00:21.000Z","updated_at":"2022-11-18T10:14:11.000Z","dependencies_parsed_at":"2023-01-22T19:30:59.879Z","dependency_job_id":null,"html_url":"https://github.com/mewmewdevart/get_next_line","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mewmewdevart%2Fget_next_line","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mewmewdevart%2Fget_next_line/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mewmewdevart%2Fget_next_line/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mewmewdevart%2Fget_next_line/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mewmewdevart","download_url":"https://codeload.github.com/mewmewdevart/get_next_line/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240934406,"owners_count":19880992,"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":["42projects","c","file-descriptor","gnl","static-variables"],"created_at":"2025-02-26T21:18:05.791Z","updated_at":"2026-05-14T23:42:37.540Z","avatar_url":"https://github.com/mewmewdevart.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://user-images.githubusercontent.com/50052600/200047157-53df5299-3754-421d-8f00-54db98d8f9f1.png\" /\u003e\r\n\u003c/p\u003e\r\n\r\n\u003ch1 align=\"center\"\u003e\r\n Get_next_line\r\n\u003c/h1\u003e\r\n\r\n\u003cp align=\"center\"\u003e\r\n\t\u003cb\u003e\u003ci\u003eThis project is about programming a function that returns a line read from a file descriptor.\u003c/i\u003e\u003c/b\u003e\u003cbr\u003e\r\n\u003c/p\u003e\r\n\r\n\u003cp align=\"center\"\u003e\r\n\t\u003cimg alt=\"Number of lines of code\" src=\"https://img.shields.io/tokei/lines/github/mewmewdevart/get_next_line?color=6272a4\" /\u003e\r\n\t\u003cimg alt=\"GitHub code size in bytes\" src=\"https://img.shields.io/github/languages/code-size/mewmewdevart/get_next_line?color=6272a4\" /\u003e\r\n\t\u003cimg alt=\"Main language\" src=\"https://img.shields.io/github/languages/top/mewmewdevart/get_next_line?color=6272a4\"/\u003e\r\n\t\u003cimg alt=\"Main language\" src=\"https://img.shields.io/github/license/mewmewdevart/get_next_line?color=6272a4\"/\u003e\r\n\u003c/p\u003e\r\n\r\n## 💡 About the project\r\n\r\n\u003e _This project introduces the concepts of _static variables_, _dynamic memory allocation_, _file descriptors_ and _macros_ while solving one simple task: that of using the Linux standard function `read()` to scan a file for _single lines_ (i.e. strings of chars with a single trailing `\\n` (new line character)).\r\n\r\n## 📁 Files/src\r\n* [`get_next_line.c`](src/get_next_line.c)\r\n\tFunction implementation. \u003cbr\u003e\r\n\t- ```ft_found_error``` finds an error in input \u003cbr\u003e\r\n\t- ```ft_free``` de-allocate the memory\r\n\t- ```ft_slice``` slice the string into pieces\r\n\t- ```ft_substr``` returns a substring from a string\r\n\r\n* [`get_next_line_utils.c`](src/get_next_line_utils.c)\r\n\tAuxiliary functions (project requirement). \u003cbr\u003e\r\n\t- ```ft_strlen``` calculate the length of a string\r\n\t- ```ft_strchr``` locate character in string\r\n\t- ```ft_strjoin``` concatenates two strings\r\n\t- ```ft_strlcpy``` concatenate string to an specific size\r\n\t- ```ft_strdup``` creates a dupplicate for the string passed as parameter\r\n\r\n* [`get_next_line.h`](src/get_next_line.h)\r\n\tHeader file.\r\n\r\n* [`main.c`](src/main.c)\r\n\tPrinting loop iterating over the file : calls get_next_line to fetch each line, then prints.\r\n\r\n* ```*_bonus.c``` \r\n\t The files is exact copies of corresponding files but with the challenge you can read from the file descriptors 3, 4 and 5, to doing able to read from a different fd per call without losing the reading thread of each file descriptor or returning a line from another.\r\n\r\n## 🛠️ Usage\r\n\r\n### Requirements\r\nThis project requires [GNU Compiler Collection](https://gcc.gnu.org/) and [GNU Make](https://www.gnu.org/software/make/) compiler. \u003cbr\u003e\r\n❗️| Make sure you have all the required tools installed on your local machine then continue with these steps.\r\n\r\n### Instructions\r\nThis function is not a stand-alone program, its files must be included and compiled within another project.\r\n\r\n**0. Download the archives**\r\n\r\nDownload the archives and go to the folder directory:\r\n\r\n```bash\r\n# Clone the repository\r\n$ git clone https://github.com/mewmewdevart/get_next_line\r\n\r\n# Enter into the directory\r\n$ cd get_next_line/src/\r\n```\r\n\r\n**1. Using it in your code**\r\n\r\nTo use the function in your code, simply include its header:\r\n\r\n```c\r\n#include \"get_next_line.h\"\r\n```\r\nAnd create a main with some inserts. \u003cbr\u003e\r\nExample ``main.c``:\r\n```c  \r\n#include \"get_next_line.h\"\r\n#include \u003cstdio.h\u003e\r\n#include \u003cfcntl.h\u003e\r\n\r\nint\tmain(int argc, char **argv)\r\n{\r\n\tint\t\tfd;\r\n\tchar\t*line;\r\n\r\n\t(void)argc;\r\n\tfd = open(argv[1], O_RDONLY);\r\n\tif (fd == -1)\r\n\t{\r\n\t\tprintf(\"open() error\\n\");\r\n\t\treturn (1);\r\n\t}\r\n\tline = \"\";\r\n\twhile (line != NULL)\r\n\t{\r\n\t\tline = get_next_line(fd);\r\n\t\tprintf(\"%s\", line);\r\n\t\tfree(line);\r\n\t}\r\n\tfd = close(fd);\r\n\tif (fd == -1)\r\n\t{\r\n\t\tprintf(\"close() error\\n\");\r\n\t\treturn (1);\r\n\t}\r\n\tprintf(\"%d\", fd);\r\n\treturn (0);\r\n}\r\n```\r\n\r\n**2. Compilation**\r\n\r\n When compiling your code, add the source files and the required flag:\r\n\r\n```shell\r\n$ gcc get_next_line_utils.c get_next_line.c main.c -D BUFFER_SIZE=\u003csize\u003e -o get_next_line\r\n```\r\nHere `BUFFER_SIZE` determines the size of the buffer used to read the file (in other words, how manny chars shall be read at once with every `read()` call).\r\nTo run the program, enter the following in the command prompt:\r\n\r\n```shell\r\n$ ./get_next_line [file.txt]\r\n```\r\nOutput should show the entire contents of the given file followed by a newline \\n.\r\n\r\n\r\n\r\n## 📋 Credits\r\n\r\n* [Acelera/Rodsmade](https://github.com/rodsmade/Projets_42_SP/)\r\n* [gnlTester/Tripouille](https://github.com/Tripouille/gnlTester)\r\n* [Resources/Mcombeau](https://github.com/mcombeau)\r\n\r\n\u003cp align=\"center\"\u003e Developed with love 💜 by Larissa Cristina Benedito (Mewmew/Larcrist). \u003c/p\u003e\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmewmewdevart%2Fget_next_line","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmewmewdevart%2Fget_next_line","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmewmewdevart%2Fget_next_line/lists"}