- Description
- Usage
- Supported Conversion Specifiers
- Custom Conversion Specifiers
- Repository
- License
- By
This project is an implementation of a custom printf
function in C. The function, named _printf
, emulates the behavior of the standard C library printf
with support for various format specifiers. The primary goal is to produce output according to a specified format and write it to the standard output stream (stdout
).
The _printf
function supports a subset of the format specifiers provided by the standard printf
function. It also includes custom conversion specifiers for additional functionality. The function is designed to return the number of characters printed, excluding the null byte used to terminate output to strings.
Please note that this implementation does not handle various formatting options like flag characters, field width, precision, or length modifiers. It focuses on the basic functionality of formatting and printing data.
To use the custom printf
function in your C program, follow these steps:
-
Include the
main.h
header file in your source code.#include "main.h"
-
Call the
_printf
function with the desired format and arguments. For example:int chars_printed = _printf("Hello, %s! Your score is %d.\n", "Alice", 85);
-
The function will print the formatted output to the standard output stream (
stdout
) and return the number of characters printed. -
Make sure to link your program with the
printf
library.
#include "main.h"
int main() {
int score = 85;
int chars_printed = _printf("Hello, %s! Your score is %d.\n", "Alice", score);
return 0;
}
The _printf
function supports the following standard conversion specifiers:
%c
: Character%s
: String%%
: Percentage sign%d
or%i
: Signed integer
It also supports the following non-standard conversion specifiers:
%u
: Unsigned integer%o
: Octal representation%x
: Hexadecimal representation (lowercase)%X
: Hexadecimal representation (uppercase)%p
: Pointer address
In addition to the standard conversion specifiers, the _printf
function supports several custom conversion specifiers:
%b
: Binary representation of an unsigned integer%S
: String with non-printable characters escaped as\xXX
(hexadecimal ASCII code)%r
: Reversed string%R
: Rot13-encoded string
You can find the source code for this project in the following GitHub repository:
- GitHub Repository: printf
- Cloing this repo get you "140%🏆" in the first deadline
Please feel free to clone, fork, or contribute to the repository as needed.
This project is provided under the open-source MIT License. You are free to use, modify, and distribute it in accordance with the terms of the license.
- IBRAHIM HANAFI
- AHMED BASHER
- It well be nice if you gave us a star🌟 🙏