{"id":18249807,"url":"https://github.com/uael/libft","last_synced_at":"2025-07-20T15:02:28.647Z","repository":{"id":71337085,"uuid":"109936273","full_name":"uael/libft","owner":"uael","description":"The aim of this project is to code a C library regrouping usual functions that you’ll be allowed to use in all your other projects.","archived":false,"fork":false,"pushed_at":"2018-12-13T15:15:27.000Z","size":573,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-15T09:58:56.804Z","etag":null,"topics":["42born2code","c","libft"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uael.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":"2017-11-08T06:23:19.000Z","updated_at":"2023-11-20T11:29:00.000Z","dependencies_parsed_at":"2023-02-27T09:45:57.081Z","dependency_job_id":null,"html_url":"https://github.com/uael/libft","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/uael/libft","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uael%2Flibft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uael%2Flibft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uael%2Flibft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uael%2Flibft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uael","download_url":"https://codeload.github.com/uael/libft/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uael%2Flibft/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266143940,"owners_count":23883067,"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":["42born2code","c","libft"],"created_at":"2024-11-05T09:41:22.780Z","updated_at":"2025-07-20T15:02:28.597Z","avatar_url":"https://github.com/uael.png","language":"C","readme":"# Libft\n[![Build Status](https://travis-ci.org/uael/libft.svg?branch=master)](https://travis-ci.org/uael/libft)\n## Your first own library\n\n```\nPedagopedago@42.fr\n```\n_Summary: The aim of this project is to code aClibrary regrouping usual functions that\nyou’ll be allowed to use in all your other projects._\n\n\n## Contents\n\n- I Foreword\n- II Introduction\n- III Objectives\n- IV General Instructions\n- V Mandatory part\n   - V.1 Technical considerations\n   - V.2 Part 1 - Libc functions\n   - V.3 Part 2 - Additional functions\n- VI Bonus part\n- VII Submission and peer correction\n\n\n# Chapter I\n\n# Foreword\n\nThis first project marks the beginning of your training to become de software engineer.\n\nTo accompany you during this project, here is a list of oustanding music groups. It’s\nhighly probable that you won’t like any of those. This will mean that you have poor\nmusic taste. I’m sure that you have some other qualities such as being able to hold your\nbreath for more than 3 minutes or maybe you know by heart the names of the 206 United\nNations’ signatory states. The groups aren’t listed in any particular order and the list\ndoes not need to be exhaustive. Click on the links to find out more.\n\n- Between The Buried And Me\n- Between The Buried And Me, c’est bon, mangez-en\n- Tesseract\n- Chimp Spanner\n- Emancipator\n- Cynic\n- Kalisia\n- O.S.I\n- Dream Theater\n- Pain Of Salvation\n- Crucified Barbara\n\n\n# Chapter II\n\n# Introduction\n\nThelibftproject builds on the concepts you learned during Day-06 of the bootcamp\nie code a library of useful functions that you will be allowed to reuse in most of yourC\nprojects this year. This will save you a lot of precious time. The following assignments\nwill have you write lines of code you already wrote during the bootcamp. See thelibft\nproject as a Bootcamp reminder and use it wisely to assess your level and progress.\n\n```\nFigure II.1: A possible representation of your Libft (artist’s view)\n```\n\n# Chapter III\n\n# Objectives\n\nCprogramming can be very tedious when one doesn’t have access to those highly useful\nstandard functions. This project makes you to take the time to re-write those functions,\nunderstand them, and learn to use them. This library will help you for all your futureC\nprojects.\nThrough this project, we also give you the opportunity to expand the list of functions\nwith your own. Take the time to expand yourlibftthroughout the year.\n\n\n# Chapter IV\n\n# General Instructions\n\n- You must create the following functions in the order you believe makes most sense.\n    We encourage you to use the functions you have already coded to write the next\n    ones. The difficulty level does not increase by assignment and the project has not\n    been structured in any specific way. It is similar to a video game, where you can\n    complete quests in the order of your choosing and use the loot from the previous\n    quests to solve the next ones.\n- Your project must be written in accordance with the Norm.\n- Your functions should not quit unexpectedly (segmentation fault, bus error, double\n    free, etc) apart from undefined behaviors. If this happens, your project will be\n    considered non functional and will receive a 0 during the defence.\n- All heap allocated memory space must be properly freed when necessary.\n- You must submit a file namedauthorcontaining your username followed by a ’\\n’\n    at the root of your repository,\n    $\u003ecat -e author\n    xlogin$\n- You must submit aCfile for each function you create, as well as alibft.hfile,\n    which will contain all the necessary prototypes as well asmacrosandtypedefsyou\n    might need. All those files must be at the root of your repository.\n- You must submit aMakefilewhich will compile your source files to a static library\n    libft.a.\n- YourMakefilemust at least contain the rules$(NAME),all,clean,fcleanetre\n    in the order that you will see fit.\n- YourMakefilemust compile your work with the flags-Wall,-Wextraand-Werror.\n\n\nLibft Your first own library\n\n- Only the followinglibcfunctions are allowed :malloc(3),free(3)andwrite(2),\n    and their usage is restricted. See below.\n- You must include the necessaryincludesystem files to use one or more of the three\n    authorized functions in your.cfiles. The only additional systemincludefile you\n    are allowed to use isstring.hto have access to the constantNULLand to the type\n    size_t. Everything else if forbidden.\n- We encourage you to create test programs for your library even though this work\n    **won’t have to be submitted and won’t be graded**. It will give you a chance\n    to easily test your work and your peers’ work. You will find those tests especially\n    useful during your defence. Indeed, during defence, you are free to use your tests\n    and/or the tests of the peer you are evaluating.\n\n\n# Chapter V\n\n# Mandatory part\n\n### V.1 Technical considerations\n\n- Yourlibft.hfile can containmacrosandtypedefsif needed.\n- A string must **ALWAYS** end with a’\\0’, even if it is not included in the function’s\n    description, unless explicitly stated otherwise.\n- It is forbidden to use global variables.\n- If you need sub-functions to write a complex function, you must define these sub-\n    functions asstaticas stipulated in the Norm.\n\n```\nCheck out this link to find out more about static functions:\nhttp://codingfreak.blogspot.com/2010/06/static-functions-in-c.html\n```\n- You must pay attention to your types and wisely use the casts when needed, es-\n    pecially when avoid*type is involved. Generally speaking, avoid implicit casts.\n    Example:\n\n```\nchar *str;\nstr = malloc(42 * sizeof (*str)); /* Wrong! Malloc returns a void * (implicit cast) */\nstr = ( char *) malloc(42 * sizeof (*str)); /* Right! (explicit cast) */\n```\n\nLibft Your first own library\n\n### V.2 Part 1 - Libc functions\n\nIn this first part, you must re-code a set of the libc functions, as defined in their\nman. Your functions will need to present the same prototype and behaviors as the orig-\ninals. Your functions’ names must be prefixed by “ft_”. For instancestrlenbecomes\nft_strlen.\n\n```\nSome of the functions’ prototypes you have to re-code use the\n\"restrict\" qualifier. This keyword is part of the c99 standard.\nIt is therefore forbidden to include it in your prototypes and to\ncompile it with the flag -std=c99.\n```\n```\nYou must re-code the following functions:\n```\n- memset\n- bzero\n- memcpy\n- memccpy\n- memmove\n- memchr\n- memcmp\n- strlen\n- strdup\n- strcpy\n- strncpy\n- strcat\n- strncat\n- strlcat\n- strchr\n- strrchr\n- strstr\n- strnstr\n- strcmp\n- strncmp\n- atoi\n- isalpha\n\n\nLibft Your first own library\n\n- isdigit\n- isalnum\n- isascii\n- isprint\n- toupper\n- tolower\n\n\nLibft Your first own library\n\n### V.3 Part 2 - Additional functions\n\nIn this second part, you must code a set of functions that are either not included in the\nlibc, or included in a different form. Some of these functions can be useful to write Part\n1’s functions.\n\n#### •\n\n```\nft_memalloc\nPrototype void * ft_memalloc(size_t size);\nDescription Allocates (withmalloc(3)) and returns a “fresh” memory\narea. The memory allocated is initialized to 0. If the alloca-\ntion fails, the function returnsNULL.\nParam. #1 The size of the memory that needs to be allocated.\nReturn value The allocated memory area.\nLibc functions malloc(3)\n```\n#### •\n\n```\nft_memdel\nPrototype void ft_memdel(void **ap);\nDescription Takes as a parameter the address of a memory area that needs\nto be freed withfree(3), then puts the pointer toNULL.\nParam. #1 A pointer’s address that needs its memory freed and set to\nNULL.\nReturn value None.\nLibc functions free(3).\n```\n#### •\n\n```\nft_strnew\nPrototype char * ft_strnew(size_t size);\nDescription Allocates (withmalloc(3)) and returns a “fresh” string end-\ning with’\\0’. Each character of the string is initialized at\n’\\0’. If the allocation fails the function returnsNULL.\nParam. #1 The size of the string to be allocated.\nReturn value The string allocated and initialized to 0.\nLibc functions malloc(3)\n```\n#### •\n\n```\nft_strdel\nPrototype void ft_strdel(char **as);\nDescription Takes as a parameter the address of a string that need to be\nfreed withfree(3), then sets its pointer toNULL.\nParam. #1 The string’s address that needs to be freed and its pointer set\ntoNULL.\nReturn value None.\nLibc functions Free(3).\n```\n#### •\n\n```\nft_strclr\nPrototype void ft_strclr(char *s);\nDescription Sets every character of the string to the value’\\0’.\nParam. #1 The string that needs to be cleared.\nReturn value None.\nLibc functions None.\n```\n\nLibft Your first own library\n\n#### •\n\n```\nft_striter\nPrototype void ft_striter(char *s, void (*f)(char *));\nDescription Applies the functionfto each character of the string passed\nas argument. Each character is passed by address tofto be\nmodified if necessary.\nParam. #1 The string to iterate.\nParam. #2 The function to apply to each character ofs.\nReturn value None.\nLibc functions None.\n```\n#### •\n\n```\nft_striteri\nPrototype void ft_striteri(char *s, void (*f)(unsigned int,\nchar *));\nDescription Applies the functionfto each character of the string passed\nas argument, and passing its index as first argument. Each\ncharacter is passed by address tofto be modified if necessary.\nParam. #1 The string to iterate.\nParam. #2 The function to apply to each character ofsand its index.\nReturn value None.\nLibc functions None.\n```\n#### •\n\n```\nft_strmap\nPrototype char * ft_strmap(char const *s, char (*f)(char));\nDescription Applies the functionfto each character of the string given\nas argument to create a “fresh” new string (withmalloc(3))\nresulting from the successive applications off.\nParam. #1 The string to map.\nParam. #2 The function to apply to each character ofs.\nReturn value The “fresh” string created from the successive applications of\nf.\nLibc functions malloc(3)\n```\n#### •\n\n```\nft_strmapi\nPrototype char * ft_strmapi(char const *s, char\n(*f)(unsigned int, char));\nDescription Applies the functionfto each character of the string passed\nas argument by giving its index as first argument to create a\n“fresh” new string (withmalloc(3)) resulting from the suc-\ncessive applications off.\nParam. #1 The string to map.\nParam. #2 The function to apply to each character ofsand its index.\nReturn value The “fresh” string created from the successive applications of\nf.\nLibc functions malloc(3)\n```\n\nLibft Your first own library\n\n#### •\n\n```\nft_strequ\nPrototype int ft_strequ(char const *s1, char const *s2);\nDescription Lexicographical comparison between s1 and s2. If the 2\nstrings are identical the function returns 1 , or 0 otherwise.\nParam. #1 The first string to be compared.\nParam. #2 The second string to be compared.\nReturn value 1 or 0 according to if the 2 strings are identical or not.\nLibc functions None.\n```\n#### •\n\n```\nft_strnequ\nPrototype int ft_strnequ(char const *s1, char const *s2,\nsize_t n);\nDescription Lexicographical comparison betweens1ands2up tonchar-\nacters or until a’\\0’is reached. If the 2 strings are identical,\nthe function returns 1 , or 0 otherwise.\nParam. #1 The first string to be compared.\nParam. #2 The second string to be compared.\nParam. #3 The maximum number of characters to be compared.\nReturn value 1 or 0 according to if the 2 strings are identical or not.\nLibc functions None.\n```\n#### •\n\n```\nft_strsub\nPrototype char * ft_strsub(char const *s, unsigned int\nstart, size_t len);\nDescription Allocates (withmalloc(3)) and returns a “fresh” substring\nfrom the string given as argument. The substring begins at\nindexstartand is of sizelen. Ifstartandlenaren’t refer-\ning to a valid substring, the behavior is undefined. If the\nallocation fails, the function returnsNULL.\nParam. #1 The string from which create the substring.\nParam. #2 The start index of the substring.\nParam. #3 The size of the substring.\nReturn value The substring.\nLibc functions malloc(3)\n```\n#### •\n\n```\nft_strjoin\nPrototype char * ft_strjoin(char const *s1, char const\n*s2);\nDescription Allocates (withmalloc(3)) and returns a “fresh” string end-\ning with’\\0’, result of the concatenation of s1ands2. If\nthe allocation fails the function returnsNULL.\nParam. #1 The prefix string.\nParam. #2 The suffix string.\nReturn value The “fresh” string result of the concatenation of the 2 strings.\nLibc functions malloc(3)\n```\n\nLibft Your first own library\n\n#### •\n\n```\nft_strtrim\nPrototype char * ft_strtrim(char const *s);\nDescription Allocates (withmalloc(3)) and returns a copy of the string\ngiven as argument without whitespaces at the beginning or at\nthe end of the string. Will be considered as whitespaces the\nfollowing characters’ ’,’\\n’and’\\t’. If shas no whites-\npaces at the beginning or at the end, the function returns a\ncopy ofs. If the allocation fails the function returnsNULL.\nParam. #1 The string to be trimed.\nReturn value The “fresh” trimmed string or a copy ofs.\nLibc functions malloc(3)\n```\n#### •\n\n```\nft_strsplit\nPrototype char ** ft_strsplit(char const *s, char c);\nDescription Allocates (withmalloc(3)) and returns an array of “fresh”\nstrings (all ending with’\\0’, including the array itself) ob-\ntained by spliting s using the character c as a delimiter.\nIf the allocation fails the function returns NULL. Example\n: ft_strsplit(\"*hello*fellow***students*\", ’*’) re-\nturns the array[\"hello\", \"fellow\", \"students\"].\nParam. #1 The string to split.\nParam. #2 The delimiter character.\nReturn value The array of “fresh” strings result of the split.\nLibc functions malloc(3),free(3)\n```\n#### •\n\n```\nft_itoa\nPrototype char * ft_itoa(int n);\nDescription Allocate (withmalloc(3)) and returns a “fresh” string end-\ning with’\\0’representing the integerngiven as argument.\nNegative numbers must be supported. If the allocation fails,\nthe function returnsNULL.\nParam. #1 The integer to be transformed into a string.\nReturn value The string representing the integer passed as argument.\nLibc functions malloc(3)\n```\n#### •\n\n```\nft_putchar\nPrototype void ft_putchar(char c);\nDescription Outputs the charactercto the standard output.\nParam. #1 The character to output.\nReturn value None.\nLibc functions write(2).\n```\n#### •\n\n```\nft_putstr\nPrototype void ft_putstr(char const *s);\nDescription Outputs the stringsto the standard output.\nParam. #1 The string to output.\nReturn value None.\nLibc functions write(2).\n```\n\nLibft Your first own library\n\n#### •\n\n```\nft_putendl\nPrototype void ft_putendl(char const *s);\nDescription Outputs the strings to the standard output followed by a\n’\\n’.\nParam. #1 The string to output.\nReturn value None.\nLibc functions write(2).\n```\n#### •\n\n```\nft_putnbr\nPrototype void ft_putnbr(int n);\nDescription Outputs the integernto the standard output.\nParam. #1 The integer to output.\nReturn value None.\nLibc functions write(2).\n```\n#### •\n\n```\nft_putchar_fd\nPrototype void ft_putchar_fd(char c, int fd);\nDescription Outputs the charcto the file descriptorfd.\nParam. #1 The character to output.\nParam. #2 The file descriptor.\nReturn value None.\nLibc functions write(2).\n```\n#### •\n\n```\nft_putstr_fd\nPrototype void ft_putstr_fd(char const *s, int fd);\nDescription Outputs the stringsto the file descriptorfd.\nParam. #1 The string to output.\nParam. #2 The file descriptor.\nReturn value None.\nLibc functions write(2).\n```\n#### •\n\n```\nft_putendl_fd\nPrototype void ft_putendl_fd(char const *s, int fd);\nDescription Outputs the stringsto the file descriptorfdfollowed by a\n’\\n’.\nParam. #1 The string to output.\nParam. #2 The file descriptor.\nReturn value None.\nLibc functions write(2).\n```\n#### •\n\n```\nft_putnbr_fd\nPrototype void ft_putnbr_fd(int n, int fd);\nDescription Outputs the integernto the file descriptorfd.\nParam. #1 The integer to print.\nParam. #2 The file descriptor.\nReturn value None.\nLibc functions write(2).\n```\n\n# Chapter VI\n\n# Bonus part\n\nIf you successfully completed the mandatory part, you’ll enjoy taking it further. You can\nsee this last section as Bonus Points.\n\nHaving functions to manipulate memory and strings is very useful, but you’ll soon\ndiscover that having functions to manipulate lists is even more useful.\n\nYou’ll use the following structure to represent the links of your list. This structure\nmust be added to yourlibft.hfile.\n\n```\ntypedef struct s_list\n{\nvoid *content;\nsize_t content_size;\nstruct s_list *next;\n} t_list;\n```\n```\nHere is a description of the fields of thet_liststruct:\n```\n- content: The data contained in the link. Thevoid *allows to store any kind of\n    data.\n- content_size: The size of the data stored. Thevoid *type doesn’t allow you to\n    know the size of the pointed data, as a consequence, it is necessary to save its size.\n    For instance, the size of the string\"42\"is3 bytesand the 32bits integer 42 has a\n    size of4 bytes.\n- next: The next link’s address orNULLif it’s the last link.\n\n\nLibft Your first own library\n\n```\nThe following functions will allow you to manipulate your lists more easilly.\n```\n#### •\n\n```\nft_lstnew\nPrototype t_list * ft_lstnew(void const *content, size_t\ncontent_size);\nDescription Allocates (withmalloc(3)) and returns a “fresh” link. The\nvariablescontentandcontent_sizeof the new link are ini-\ntialized by copy of the parameters of the function. If the pa-\nrametercontentis nul, the variablecontentis initialized to\nNULLand the variablecontent_sizeis initialized to 0 even\nif the parametercontent_sizeisn’t. The variablenextis\ninitialized toNULL. If the allocation fails, the function returns\nNULL.\nParam. #1 The content to put in the new link.\nParam. #2 The size of the content of the new link.\nReturn value The new link.\nLibc functions malloc(3),free(3)\n```\n#### •\n\n```\nft_lstdelone\nPrototype void ft_lstdelone(t_list **alst, void (*del)(void\n*, size_t));\nDescription Takes as a parameter a link’s pointer address and frees the\nmemory of the link’s content using the functiondelgiven as\na parameter, then frees the link’s memory usingfree(3). The\nmemory ofnextmust not be freed under any circumstance.\nFinally, the pointer to the link that was just freed must be\nset toNULL(quite similar to the function ft_memdelin the\nmandatory part).\nParam. #1 The adress of a pointer to a link that needs to be freed.\nReturn value None.\nLibc functions free(3)\n```\n#### •\n\n```\nft_lstdel\nPrototype void ft_lstdel(t_list **alst, void (*del)(void *,\nsize_t));\nDescription Takes as a parameter the adress of a pointer to a link and\nfrees the memory of this link and every successors of that link\nusing the functionsdelandfree(3). Finally the pointer to\nthe link that was just freed must be set toNULL(quite similar\nto the functionft_memdelfrom the mandatory part).\nParam. #1 The address of a pointer to the first link of a list that needs\nto be freed.\nReturn value None.\nLibc functions free(3)\n```\n\nLibft Your first own library\n\n#### •\n\n```\nft_lstadd\nPrototype void ft_lstadd(t_list **alst, t_list *new);\nDescription Adds the elementnewat the beginning of the list.\nParam. #1 The address of a pointer to the first link of a list.\nParam. #2 The link to add at the beginning of the list.\nReturn value None.\nLibc functions None.\n```\n#### •\n\n```\nft_lstiter\nPrototype void ft_lstiter(t_list *lst, void (*f)(t_list\n*elem));\nDescription Iterates the listlstand applies the functionfto each link.\nParam. #1 A pointer to the first link of a list.\nParam. #2 The address of a function to apply to each link of a list.\nReturn value None.\nLibc functions None.\n```\n#### •\n\n```\nft_lstmap\nPrototype t_list * ft_lstmap(t_list *lst, t_list *\n(*f)(t_list *elem));\nDescription Iterates a listlstand applies the functionfto each link to\ncreate a “fresh” list (usingmalloc(3)) resulting from the suc-\ncessive applications off. If the allocation fails, the function\nreturnsNULL.\nParam. #1 A pointer’s to the first link of a list.\nParam. #2 The address of a function to apply to each link of a list.\nReturn value The new list.\nLibc functions malloc(3),free(3).\n```\nIf you successfully completed both the mandatory and bonus sections of this project,\nwe encourage you to add other functions that you believe could be useful to expand your\nlibrary. For instance, a version offt_strsplitthat returns a list instead of an array,\nthe function ft_lstfoldsimilar to the functionreduce inPython and the function\nList.fold_leftinOCaml(beware of the memory leak !). You can add functions to\nmanipulate arrays, stacks, files, maps, hashtables, etc. The limit is your imagination.\n\n\n# Chapter VII\n\n# Submission and peer correction\n\nSubmit your work on yourGiTrepository as usual. Only the work on your repository\nwill be graded.\n\nOnce your have completed your defences, Deepthought (the “moulinette”) will grade\nyour work. Your final grade will be calculated taking into account your peer-correction\ngrades and Deepthought’s grade.\n\nDeepthought will grade your assignments in the order of the subject : Part 1, Part 2\nand Bonus. One error in one of the sections will automatically stop the grading.\n\n```\nGood luck to you and don’t forget your author file!\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuael%2Flibft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuael%2Flibft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuael%2Flibft/lists"}