This repository contains a custom implementation of the printf
function with support for various conversion specifiers. Below is a list of tasks and features included in this project.
Create a custom printf function that supports basic conversions, such as printing characters, strings, and percent signs.
Extend the printf function to handle 'd' and 'i' conversions (decimal and integer).
Implement a custom conversion specifier '%b' to print unsigned integers in binary format.
Extend the printf function to handle 'u', 'o', 'x', and 'X' conversions (unsigned, octal, hexadecimal lower-case, and hexadecimal upper-case).
Optimize the function using a local buffer of 1024 characters to reduce the number of write calls.
Implement a custom conversion specifier '%S' to print strings with non-printable characters represented as '\x' followed by their ASCII code in hexadecimal.
Handle the 'p' conversion specifier (print memory address).
Implement support for flag characters '+', 'space', and '#' for non-custom conversion specifiers.
Handle length modifiers 'l' and 'h' for non-custom conversion specifiers 'd', 'i', 'u', 'o', 'x', and 'X'.
Implement support for the field width for non-custom conversion specifiers.
Implement support for the precision for non-custom conversion specifiers.
Handle the flag character '0' for non-custom conversion specifiers (padding with zeros).
Handle the flag character '-' for non-custom conversion specifiers (left-justify).
Implement a custom conversion specifier '%r' to print the reversed string.
Implement a custom conversion specifier '%R' to print the rot13'ed string.
Ensure that all the above options work well together.
-
Custom printf function for basic conversions
- Create a function
int _printf(const char *format, ...)
that mimics the behavior of the standardprintf
function. - The function should support the following conversion specifiers:
%c
: Print a character.%s
: Print a string.%%
: Print a percent sign.
- The function should return the number of characters printed (excluding the null byte).
- Create a function
Repo: printf
-
Support for 'd' and 'i' conversions
- Extend the
_printf
function to handle the 'd' and 'i' conversion specifiers.
Repo: printf
- Extend the
-
Handle custom conversion specifier 'b'
- Implement a custom conversion specifier '%b' to print an unsigned integer in binary format.
- Example:
_printf("%b\n", 98);
output >> 1100010
Repo: printf
-
Support for 'u', 'o', 'x', and 'X' conversions
- Extend the
_printf
function to handle the 'u', 'o', 'x', and 'X' conversion specifiers.
Repo: printf
- Extend the
-
Optimize with a local buffer
- Use a local buffer of 1024 characters to minimize the number of calls to the
write
function.
Repo: printf
- Use a local buffer of 1024 characters to minimize the number of calls to the
-
Handle custom conversion specifier 'S'
- Implement a custom conversion specifier '%S' to print strings with non-printable characters represented as '\x' followed by their ASCII code in hexadecimal.
- Example:
_printf("%S\n", "Best\nSchool");
output >> Best\x0ASchool
Repo: printf
-
Handle conversion specifier 'p'
- Extend the
_printf
function to handle the 'p' conversion specifier.
Repo: printf
- Extend the
-
Handle flag characters '+', 'space', and '#'
- Implement support for the flag characters '+', 'space', and '#' for non-custom conversion specifiers.
Repo: printf
-
Handle length modifiers 'l' and 'h'
- Implement support for the length modifiers 'l' and 'h' for non-custom conversion specifiers 'd', 'i', 'u', 'o', 'x', and 'X'.
Repo: printf
-
Handle field width
- Implement support for the field width for non-custom conversion specifiers.
Repo: printf
-
Handle precision
- Implement support for the precision for non-custom conversion specifiers.
Repo: printf
- Handle flag character '0'
- Implement support for the flag character '0' for non-custom conversion specifiers.
Repo: printf
- Handle flag character '-'
- Implement support for the flag character '-' for non-custom conversion specifiers.
Repo: printf
- Handle custom conversion specifier 'r'
- Implement a custom conversion specifier '%r' to print the reversed string.
Repo: printf
- Handle custom conversion specifier 'R'
- Implement a custom conversion specifier '%R' to print the rot13'ed string.
Repo: printf
- Integration of all options
- Ensure that all the above options work well together.
Repo: printf