{"id":19483541,"url":"https://github.com/librity/ft_printf","last_synced_at":"2025-07-03T12:05:20.121Z","repository":{"id":99703271,"uuid":"341691740","full_name":"librity/ft_printf","owner":"librity","description":"42 São Paulo - ft_printf","archived":false,"fork":false,"pushed_at":"2022-08-06T19:30:42.000Z","size":1232,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T17:46:15.002Z","etag":null,"topics":["42","42born2code","42saopaulo","c","printf-42"],"latest_commit_sha":null,"homepage":"https://www.42sp.org.br/","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/librity.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-23T21:12:58.000Z","updated_at":"2021-12-29T01:26:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"9af15222-b156-4dd7-bd41-d976e3daa316","html_url":"https://github.com/librity/ft_printf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/librity/ft_printf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fft_printf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fft_printf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fft_printf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fft_printf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/librity","download_url":"https://codeload.github.com/librity/ft_printf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fft_printf/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263322788,"owners_count":23448713,"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","42born2code","42saopaulo","c","printf-42"],"created_at":"2024-11-10T20:15:30.274Z","updated_at":"2025-07-03T12:05:20.089Z","avatar_url":"https://github.com/librity.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch3 align=\"center\"\u003e42 São Paulo - ft_printf\u003c/h3\u003e\r\n\r\n\u003cdiv align=\"center\"\u003e\r\n\r\n![42 São Paulo](https://img.shields.io/badge/42-SP-1E2952)\r\n![License](https://img.shields.io/github/license/librity/ft_printf?color=yellow)\r\n![Code size in bytes](https://img.shields.io/github/languages/code-size/librity/ft_printf?color=blue)\r\n![Lines of code](https://img.shields.io/tokei/lines/github/librity/ft_printf?color=blueviolet)\r\n![Top language](https://img.shields.io/github/languages/top/librity/ft_printf?color=ff69b4)\r\n![Last commit](https://img.shields.io/github/last-commit/librity/ft_printf?color=orange)\r\n\r\n\u003c/div\u003e\r\n\r\n\u003cdiv align=\"center\"\u003e\r\n\r\n[![Norminette v3](https://github.com/librity/ft_printf/actions/workflows/norminette_v3.yml/badge.svg)](https://github.com/librity/ft_printf/actions/workflows/norminette_v3.yml)\r\n[![Build](https://github.com/librity/ft_printf/actions/workflows/build.yml/badge.svg)](https://github.com/librity/ft_printf/actions/workflows/build.yml)\r\n[![FT_PRINTF_TEST](https://github.com/librity/ft_printf/actions/workflows/FT_PRINTF_TEST.yml/badge.svg)](https://github.com/librity/ft_printf/actions/workflows/FT_PRINTF_TEST.yml)\r\n[![42TESTERS-PRINTF](https://github.com/librity/ft_printf/actions/workflows/42TESTERS-PRINTF.yml/badge.svg)](https://github.com/librity/ft_printf/actions/workflows/42TESTERS-PRINTF.yml)\r\n[![PFT_2019](https://github.com/librity/ft_printf/actions/workflows/PFT_2019.yml/badge.svg)](https://github.com/librity/ft_printf/actions/workflows/PFT_2019.yml)\r\n\r\n\u003c/div\u003e\r\n\r\n\u003cp align=\"center\"\u003e A partial implementation of printf in pure C.\r\n    \u003cbr\u003e\r\n\u003c/p\u003e\r\n\r\n---\r\n\r\n## 📜 Table of Contents\r\n\r\n- [About](#about)\r\n- [Getting Started](#getting_started)\r\n- [Usage](#usage)\r\n- [Testers](#testers)\r\n- [Github Actions](#github_actions)\r\n- [42 São Paulo](#ft_sp)\r\n\r\n## 🧐 About \u003ca name = \"about\"\u003e\u003c/a\u003e\r\n\r\nThis is the third project I did at 42 São Paulo:\r\nan implementation of the famous `printf` function from scratch.\r\n\r\nIt was a big project and my first milestone at 42:\r\nI felt properly challenged and out of my comfort zone throughout most of it.\r\nIt taught me how to organize code effectively in C,\r\nand to separate responsibilities without resorting to\r\nClasses and Objects (which is what I'm used to).\r\n\r\nI managed to do it without using a single `malloc` or `free`,\r\nbut with pointers to stack structs that I pass around to each handler.\r\nThere's an isolated struct, handler, and formatter for each conversion.\r\n\r\nThe only thing that conversion \"modules\" share are\r\nthe flag parser and pure utility functions.\r\nI did it this way so I didn't need to worry about breaking the formatting\r\nof other conversions as I tinkered with the rules.\r\n\r\nThis was a really good decision since there are many formatting exceptions\r\nand flag combinations that vary from conversion to conversion,\r\nand it sure saved me some headaches.\r\n\r\n## 🏁 Getting Started \u003ca name = \"getting_started\"\u003e\u003c/a\u003e\r\n\r\n### ⚙️ Prerequisites\r\n\r\nAll you need is a shell and a C compiler like `gcc` or `clang`.\r\n\r\n### 🖥️ Installing\r\n\r\nTo compile the entire thing just clone the repo and run `make`:\r\n\r\n```bash\r\n$ git clone https://github.com/librity/ft_printf.git\r\n$ cd ft_printf\r\n$ make\r\n```\r\n\r\nThis will generate a `ft_printf.a` archive, which you can compile with\r\nany of the example files:\r\n\r\n```bash\r\n$ cp examples/example_1.c example.c\r\n$ gcc -g -I ./includes example.c ft_printf.a\r\n$ ./a.out\r\n```\r\n\r\n## 🎈 Usage \u003ca name=\"usage\"\u003e\u003c/a\u003e\r\n\r\nYou can call `ft_printf` as you would call your system's `printf` function:\r\n\r\n```c\r\nft_printf(\"'%-10s'\\n\", \"Hello, world!\");\r\n```\r\n\r\nIt handles most conversions:\r\n\r\n- Percent `char`: `%%`\r\n- Unsigned `char`: `%c`\r\n- Signed decimal `int`: `%i` or `%d`\r\n- Null-terminated `char *`: `%s`\r\n- Unsigned decimal `int`: `%u`\r\n- Uppercase hexadecimal `unsigned int`: `%X`\r\n- Lowercase hexadecimal `unsigned int`: `%x`\r\n- Pointer/hexadecimal memory address `unsigned long`: `%p`\r\n- `float` and `double`: `%f`\r\n- `long double`: `%Lf`\r\n\r\nAnd also handles almost all the flags:\r\n\r\n- Zero padding `0`\r\n- Let-justified `-`\r\n- Minimum field width\r\n- Precision `.`\r\n- Wildcard arguments `*`\r\n\r\nConversions and flags must respect the format:\r\n`%[0 and/or -][width][.number]conversion`\r\n\r\nUnfortunately there's no rigorous documentation or standard for this function,\r\nand a lot of its behavior is implementation-specific.\r\nThere are many corner-cases that need to be ironed out by trial and error.\r\nSince this is a 42 project, I replicated the behavior of Apple's `printf`.\r\n\r\n[This](https://www.cplusplus.com/reference/cstdio/printf/)\r\nis best source I could find on the project,\r\nand should be enough to get you started.\r\n\r\n## ✅ Testers \u003ca name = \"testers\"\u003e\u003c/a\u003e\r\n\r\nGithub Actions by [@wblech](https://github.com/wblech/42_github_actions)\r\n\r\n- https://github.com/cclaude42/PFT_2019\r\n- https://github.com/Mazoise/42TESTERS-PRINTF\r\n- https://github.com/cacharle/ft_printf_test\r\n\r\n## 🐙 Github Actions \u003ca name = \"github_actions\"\u003e\u003c/a\u003e\r\n\r\nNorminette v3 github action\r\nbased on [@AdrianWR](https://github.com/AdrianWR)'s\r\n[implementation](https://github.com/AdrianWR/libft/blob/master/.github/workflows/norminette.yaml).\r\n\r\n## 🛸 42 São Paulo \u003ca name = \"ft_sp\"\u003e\u003c/a\u003e\r\n\r\nPart of the larger [42 Network](https://www.42.fr/42-network/),\r\n[42 São Paulo](https://www.42sp.org.br/) is a software engineering school\r\nthat offers a healthy alternative to traditional education:\r\n\r\n- It doesn't have any teachers and classes.\r\n- Students learn by cooperating\r\n  and correcting each other's work (peer-to-peer learning).\r\n- Its focus is as much on social skills as it is on technical skills.\r\n- It's completely free to anyone that passes its selection process -\r\n  [**The Piscine**](https://42.fr/en/admissions/42-piscine/)\r\n\r\nIt's an amazing school, and I'm grateful for the opportunity.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibrity%2Fft_printf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibrity%2Fft_printf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibrity%2Fft_printf/lists"}