Skip to content
/ printf Public

This project is an implementation of the printf function, a fundamental feature in the C programming language. Our custom printf function provides the capability to format and print various types of data, including text and variables, with the same level of flexibility and functionality as the standard printf in C.

License

Notifications You must be signed in to change notification settings

hima890/printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Printf Function

Project Name: Custom printf Function 🚀

Table of Contents


Description

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.

Usage

To use the custom printf function in your C program, follow these steps:

  1. Include the main.h header file in your source code.

    #include "main.h"
  2. 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);
  3. The function will print the formatted output to the standard output stream (stdout) and return the number of characters printed.

  4. Make sure to link your program with the printf library.

Example:

#include "main.h"

int main() {
    int score = 85;
    int chars_printed = _printf("Hello, %s! Your score is %d.\n", "Alice", score);
    return 0;
}

Supported Conversion Specifiers

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

Custom Conversion Specifiers

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

Repository

You can find the source code for this project in the following GitHub repository:

Please feel free to clone, fork, or contribute to the repository as needed.

License

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.


By

  • IBRAHIM HANAFI
  • AHMED BASHER
  • It well be nice if you gave us a star🌟 🙏

About

This project is an implementation of the printf function, a fundamental feature in the C programming language. Our custom printf function provides the capability to format and print various types of data, including text and variables, with the same level of flexibility and functionality as the standard printf in C.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages