{"id":21666992,"url":"https://github.com/princexz/printf","last_synced_at":"2025-04-12T01:21:41.220Z","repository":{"id":148304770,"uuid":"593398499","full_name":"Princexz/printf","owner":"Princexz","description":"This a repository for the ALX project for the printf project","archived":false,"fork":false,"pushed_at":"2023-03-30T23:38:18.000Z","size":59,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T21:03:56.940Z","etag":null,"topics":["c","c-printf","printf","printf-functions","team-project"],"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/Princexz.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":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-25T22:37:04.000Z","updated_at":"2024-11-10T17:32:38.000Z","dependencies_parsed_at":"2023-05-19T17:15:18.726Z","dependency_job_id":null,"html_url":"https://github.com/Princexz/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/Princexz%2Fprintf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Princexz%2Fprintf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Princexz%2Fprintf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Princexz%2Fprintf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Princexz","download_url":"https://codeload.github.com/Princexz/printf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501862,"owners_count":21114685,"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":["c","c-printf","printf","printf-functions","team-project"],"created_at":"2024-11-25T11:31:52.854Z","updated_at":"2025-04-12T01:21:41.213Z","avatar_url":"https://github.com/Princexz.png","language":"C","readme":" ## ALX printf Project\n\nThis a repository for the ALX team project for the printf.\n\nThe printf() function prints output to stdout, according to format and other arguments passed to printf(). \nThe string format consists of two types of items - characters that will be printed to the screen,\nand format commands that define how the other arguments to printf() are displayed. Basically,\nyou specify a format string that has text in it, as well as \"special\" characters\nthat map to the other arguments of printf().\n\n---\n\nThe prototype of this function is: int _printf(const char format, ...);\n\nThis means that it has one mandatory format argument, and an extra number of arguments that can be none, or many.\n\nFormat of the format string\n\nThe format string is a character string starting and ending with double quotes. The format string is composed of zero or more directives; ordinary characters (not %), and conversion specifications, each of which results in fetching zero or more subsequent arguments.\n\nEach conversion specification is introduced by the character % and ends with a conversion specifier. In between there may be (in this order):\n\nZero or more flags\n\nAn optional field width\n\nAn optional precision modifier\n\nAn optional length modifier\n\n\n ## **Synopsis**\n\nThe function _printf() writes output to stdout, the standard output stream with the format and options presented below. It uses an internal buffer of 1024 bytes although it can print larger sets of data.\n\nUpon successful execution, this function returns the number of characters printed (excluding the null byte used to end output to strings).\n\nIf an output error is encountered, a negative value of -1 is returned.\n\nThe prototype of this function is the next:\n\n\u003e **int _printf(const char *format, ...);***\n\nMeaning that it has one mandatory format argument, and an extra number of arguments that can be none, or many.\n\n**Format of the format string**\n\nThe format string is a character string starting and ending with double quotes. The format string is composed of zero or more directives; ordinary characters (not %), and conversion specifications, each of which results in fetching zero or more subsequent arguments. \n\nEach conversion specification is introduced by the character **%** and ends with a **conversion specifier**. In between there may be (in this order):\n\n\u003e Zero or more **flags**\n\u003e\n\u003e An optional field **width**\n\u003e\n\u003e An optional **precision** modifier\n\u003e\n\u003e An optional **length** modifier\n\n\n# **The flag characters**\n\n|**Flag**| Description  |\n|--|--|\n|**#**| For **o** conversions the first character of the output string is made zero (by prefixing a 0 if it was not zero already).  For **x** and **X** conversions, a nonzero result has the string \"**0x**\" or \"**0X**\" respectively added. |\n|**0**| (Not implemented yet) The  value should be zero padded. For **d**, **i**, **o**, **u**, **x**, and **X** the converted value is padded on the left with zeros. If the 0 and **-** flags both appear,the **0** flag is ignored. If a precision is given with a numeric conversion, the **0** flag is ignored.|\n|**-**|(Minus sign, not implemented yet) The converted value is to be left adjusted on the field boundary, (Default is right justification) and  padded  with  blanks  in  the right rather than on the left with blanks or zeros. This flag overrides **0** if both are given.|\n|' '| (Blank Space) The argument is padded with a single blank space before a positive number or empty string produced by a signed conversion.|\n|**+**| A sign (+ or -) should always be placed before a number produced with a signed conversion.  By default, only negative numbers have this sign.|\n\n# **The field width**\n\nAn  optional decimal digit string (with nonzero first digit) specifying a minimum field width.  If  the  converted  value  has  fewer characters  than  the field width, it will be padded with spaces on the left if the flag - is not present, and on the right  if  it  is present.  A character * can be used instead of a decimal string. In this case, an argument passed to the function will be taken as  the width value.\n\n    printf(\"%5d\", num);\n\nor\n\n\tprintf(\"%*d\", width, num);\n\n**The precision**\n\n An  optional  precision,  in  the  form  of a period ('.')  followed by an optional decimal digit string.  A negative precision is taken  as  if  the precision were omitted.  This gives the minimum number of digits to appear for d, i, o, u, x, and X conversions,  or the  maximum  number of characters to be printed from a string for s and S conversions. A character * can be used instead of a  decimal string. In this case, an argument passed to the function will be taken as the precision value.\n\n    printf(\"%.3d\", num);\n\n  or\n\n    printf(\"%.*d\", precision, num);\n\n**The length modifiers**\n\n|Modifier| Description |\n|--|--|\n|**l**| An integer conversion to a **long int** or **unsigned long int** argument.  |\n|**h**| An integer conversion to a **short int** or **unsigned short int** argument. |\n\n**The conversion specifier**\n\n|Specifier| Description |\n|--|--|\n|**d, i**|The argument **int** is converted to a signed decimal notation. If precision is present,it gives the minimum number of digits that must appear; if the converted value requires fewer digits, then it is padded with zeros on the left. Default precision is 1.|\n|**o, u, x, X**|The argument is converted to unsigned octal (**o**), unsigned decimal (**u**), or unsigned hexamedical (**x** and **X**) notation. The letters abcdef are used for x conversion and the letters ABCDEF are used for X conversion. If precision is present, it will give  the  minimum  number  of  digits  that  must appear; if the converted value requires fewer digits, then it will be padded with zeros. By default the precision is 1.  |\n|**c**|The  int argument is converted to an unsigned char and the resulting character is written. The representation of characters is based off the ASCII coding.|\n|**s**|The argument received is expected to be a pointer type char * to an array of characters.  Characters from this array are printed up  to  (but  not including) a null byte  (**'\\0'**).  If precision is specified, then this will determine how many characters are taken into account for printing.|\n|**p**|A void * pointer argument is printed as hexadecimal in lower caps representing an adress in memory.|\n|**%**|A  ' **%** ' character is written and no conversion is made. The specification is as follows: **%%**. |\n|**b**|The argument is converted to an unsigned int value and then operated to get its binary representation (base 2).|\n|**S**| The  argument  received  is expected to be a pointer type char * to an array of characters.  Characters from this array are printed up to (but not including) a null byte  ('\\0').  Non printable characters (0 \u003c ASCII value \u003c 32 or \u003e= 127) are printed this way: \\x, followed by  the  ASCII  code value in hexadecimal (upper case - always 2 characters). |\n|**r**|The  argument received is expected to be a pointer type char * to an array of characters.  Characters from this array are printed in reverse order up to (but not including) a null byte  ('\\0').  |\n|**R**|The argument received is expected to be a pointer type char * to an array of characters.  Characters from this array  are  encoded  to  ROT13  and printed in order up to (but not including a null byte  ('\\0').  |\n\n---\n\n/* This header is mandatory for the function to run */\n    #include \"main.h\"\n    /**\n    * This Header is optional and allows you to compare the\n    *  custom _printf() function to the standard library one.\n    */\n    #include \u003cstdio.h\u003e\n\n    /**\n     * main - Entry point\n     *\n     * Return: Always 0\n     */\n\n    int main(void)\n    {\n        int len1, len2;\n        char *s = \"Hello\";\n\n        /* The '\\n' character is used for printing a new line */\n\n        /* Custom printf Function */\n         _printf(\"Text\\n\");\n        /* Standard Library printf Function */\n         printf(\"Text\\n\");\n         _printf(\"Hello %s\\n\", World);\n         printf(\"Hello %s\\n\", World);\n         _printf(\"I like %ctags\\n\", '#');\n         printf(\"I like %ctags\\n\", '#');\n\n         len1 = _printf(\"%s World\\n\", s);\n         len2 = printf(\"%s World\\n\", s);\n\n         _printf(\"The length was [%d]\\n\", len1);\n         printf(\"The length was [%d]\\n\", len2);\n\n\t _printf(\"Plus Sign Pos Number[%+d]\\n\", 54);\n\t _printf(\"Plus Sign Neg Number[%+d]\\n\", -54);\n\n\t _printf(\"Space Pos Number[% d]\\n\", 54);\n\t _printf(\"Space Neg Number[% d]\\n\", -54);\n\n\t _printf(\"Hash Hexadecimal[%#x]\\n\", 123);\n\t _printf(\"Hash Octal[%#o]\\n\", 123);\n\n         return (0);\n    }\n\n--- # **Compilation:**\n\nWhen you are done creating you *main.c* file  you will need to compile it. You can use any compiler software you like, although this project was tested in GNU GCC 5.5.0 with different error flags such as:\n\n\u003e **-Wall:** Enables all the warnings about constructions.\n\u003e\n\u003e **-Wextra :** Enables some extra warning flags that are not enabled by **-Wall**.\n\u003e\n\u003e **-Werror:** Make all warnings into hard errors.\n\u003e\n\u003e **-pedantic:** Issue all the mandatory diagnostics listed in the C standard.\n\u003e\n\u003e **-Wno-format:** Disables warnings about printf format (so that you can try any type of format you want) in equivalence to a custom made variadic function.\n\n    test@ubuntu:~/printf$ gcc -Wall -Wextra -Werror -pedantic -Wno-format *.c\n\n# **Execution:**\n\n    test@ubuntu:~/printf$ ./a.out\n\n\u003e **Output:**\n\u003e\n\u003e Text\n\u003e\n\u003e Text\n\u003e\n\u003e Hello World\n\u003e\n\u003e Hello World\n\u003e\n\u003e I like #tags\n\u003e\n\u003e I like #tags\n\u003e\n\u003e Hello World\n\u003e\n\u003e Hello World\n\u003e\n\u003e The length was [12]\n\u003e\n\u003e The length was [12]\n\u003e\n\u003ePlus Sign Pos Number[+54]\n\u003e\n\u003ePlus Sign Neg Number[+54]\n\u003e\n\u003eSpace Pos Number[ 54]\n\u003e\n\u003eSpace Pos Number[-54]\n\u003e\n\u003eHash Hexadecimal[0x7B]\n\u003e\n\u003eHash Octal[0173]\n\n## **Flowchart**\n\nHere is a diagram of the general behaviour of the _printf.\n\nThe most important functions are presented:\n\n_printf\n\n\n## **Flowchart**\n\nHere is a diagram of the general behaviour of the _printf.\n\nThe most important functions are presented:\n\n_printf\n\n![_printf](https://i.imgur.com/nOO6dKj.png)\n\nGenerate malloc\n\n![Generate Malloc](https://i.imgur.com/oqukAVN.png)\n\n## **Bugs**\n\nThe field width and precision modifiers are still in development, so there may be flaws with their functions.\nThe flags (-) and (0) are yet to be implemented.## **Flowchart**\n\nHere is a diagram of the general behaviour of the _printf.\n\nThe most important functions are presented:\n\n_printf\n\n![_printf](https://i.imgur.com/nOO6dKj.png)\n\nGenerate malloc\n\n![Generate Malloc](https://i.imgur.com/oqukAVN.png)\n\n## **Bugs**\n\nThe field width and precision modifiers are still in development, so there may be flaws with their functions.\nThe flags (-) and (0) are yet to be implemented.\n\n\n## Author :black_nib:\n\n* **Prince Solomon** [princexz](https://github.com/princexz)\n\n## Acknowledgements :pray:\n\nAll work contained in this project was completed as part of the curriculum for ALX Africa SE. ALX Africa is an online full-stack software engineering program that prepares students for careers in the tech industry using project-based peer learning. For more information, visit [this link](https://www.alxafrica.com//).\n\n\u003cp align=\"center\"\u003e\n  \u003cimg\n   src=\"https://www.alxafrica.com/wp-content/uploads/2022/01/header-logo.png\"\n       alt=\"ALX Africa Logo\"\n  \u003e\n\u003c/p\u003e\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprincexz%2Fprintf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprincexz%2Fprintf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprincexz%2Fprintf/lists"}