{"id":20345800,"url":"https://github.com/izzypt/ft_printf","last_synced_at":"2026-04-12T23:02:14.480Z","repository":{"id":64919065,"uuid":"578358548","full_name":"izzypt/ft_printf","owner":"izzypt","description":"The goal of this project is pretty straightforward. You will recode printf().","archived":false,"fork":false,"pushed_at":"2023-07-04T17:56:14.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-14T21:46:35.343Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/izzypt.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":"2022-12-14T21:43:11.000Z","updated_at":"2022-12-17T22:46:13.000Z","dependencies_parsed_at":"2025-01-14T21:34:37.587Z","dependency_job_id":"71da1f1f-6602-44b0-9b0b-2daaca55189c","html_url":"https://github.com/izzypt/ft_printf","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/izzypt%2Fft_printf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2Fft_printf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2Fft_printf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2Fft_printf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izzypt","download_url":"https://codeload.github.com/izzypt/ft_printf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241876613,"owners_count":20035396,"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":[],"created_at":"2024-11-14T22:09:49.411Z","updated_at":"2026-04-12T23:02:14.396Z","avatar_url":"https://github.com/izzypt.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ft_printf\nYou have to recode the printf() function from libc.\n\n| Requirements | Description |\n| --- | --- |\n| Program name  | libftprintf.a |\n| Turn in files  | Makefile, *.h, */*.h, *.c, */*.c |\n| Makefile | NAME, all, clean, fclean, re |\n| External functs| malloc, free, write, va_start, va_arg, va_copy, va_end |\n| Libft authorized | Yes |\n| Description | Write a library that contains ft_printf(), a function that will mimic the original printf()|\n\n\nThe prototype of ft_printf() is:\n  ###\n    int ft_printf(const char *, ...);\n\nHere are the requirements:\n \n    • Don’t implement the buffer management of the original printf().\n    • Your function has to handle the following conversions: cspdiuxX%\n    • Your function will be compared against the original printf().\n    • You must use the command ar to create your library.\n    Using the libtool command is forbidden.\n    • Your libftprintf.a has to be created at the root of your repository.\n\n\nYou have to implement the following conversions:\n    \n    • %c Prints a single character.\n    • %s Prints a string (as defined by the common C convention).\n    • %p The void * pointer argument has to be printed in hexadecimal format.\n    • %d Prints a decimal (base 10) number.\n    • %i Prints an integer in base 10.\n    • %u Prints an unsigned decimal (base 10) number.\n    • %x Prints a number in hexadecimal (base 16) lowercase format.\n    • %X Prints a number in hexadecimal (base 16) uppercase format.\n    • %% Prints a percent sign.\n    \n## Helpful Concepts\n\n### Variadic functions\n\n- Variadic functions are functions that can take a variable number of arguments. \n- It takes one fixed argument and then any number of arguments can be passed.\n- The variadic function consists of at least one fixed variable and then an ellipsis(…) as the last parameter.\n\nva_list, va_arg, and va_start are used to help us achieve this goal: to accept a variable number of arguments.\n\n### Introduction to va_list and Variable Argument Functions in C:\n\nIn C programming, there are situations where we need to handle functions with a variable number of arguments. To achieve this flexibility, C provides a set of macros and types in the ```stdarg.h``` header, including va_list, va_start, and va_arg. These components allow us to work with a varying number of arguments passed to a function.\n\n1. va_list:\n  - The va_list type is used to declare a variable that holds the information about the variable arguments. It serves as a handle or pointer to access each argument passed to a function.\n\n2. va_start:\n  - The va_start macro initializes the va_list object, associating it with the last known fixed argument. It allows us to start accessing the variable arguments.\n\n3. va_arg:\n  - The va_arg macro extracts the next argument from the va_list. It takes the va_list object and the type of the expected argument as parameters, returning the value of the argument in the specified type.\n\nUsage of va_list, va_start, and va_arg:\n\nLet's consider an example to understand how to use va_list, va_start, and va_arg in C:\n\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstdarg.h\u003e\n\ndouble average(int count, ...) {\n    va_list args;\n    double sum = 0;\n\n    // Initialize va_list\n    va_start(args, count);\n\n    // Access variable arguments\n    for (int i = 0; i \u003c count; ++i) {\n        double num = va_arg(args, double);\n        sum += num;\n    }\n\n    // Clean up va_list\n    va_end(args);\n\n    return sum / count;\n}\n\nint main() {\n    double avg1 = average(3, 2.5, 3.7, 4.2);\n    double avg2 = average(4, 1.0, 2.0, 3.0, 4.0);\n\n    printf(\"Average 1: %f\\n\", avg1);\n    printf(\"Average 2: %f\\n\", avg2);\n\n    return 0;\n}\n```\n\nIn this example, we define a function named `average` that calculates the average of a variable number of arguments. The function takes the count of arguments and then uses a va_list object `args` to handle the variable arguments.\n\nWithin the `average` function, we start by initializing the va_list object using `va_start(args, count)`, where `args` is the va_list object and `count` is the last known fixed argument.\n\nNext, we use a loop to access each variable argument by calling `va_arg(args, double)`, where `args` is the va_list object and `double` is the expected type of the argument. The `va_arg` macro retrieves the next argument from the va_list and casts it to the specified type.\n\nAfter accessing all the variable arguments, we clean up the va_list using `va_end(args)` to release any resources associated with it.\n\nIn the `main` function, we demonstrate the usage of the `average` function with different numbers of arguments, and then print the calculated averages using printf.\n\nBy utilizing va_list, va_start, and va_arg, we can create functions that accept a variable number of arguments and perform operations on them effectively.\n\nI hope this introduction provides a good starting point for understanding va_list and its associated macros in C programming.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzypt%2Fft_printf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizzypt%2Fft_printf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzypt%2Fft_printf/lists"}