Giter Site home page Giter Site logo

printf's Introduction

๐Ÿ–จ๏ธ Printf Project

๐Ÿ“– Overview

This project is a recreation of the famous C library function, printf. The goal is to understand the inner workings of this type of function, and recreate it.

๐Ÿ›  Usage

int ft_printf(const char *format, ...);

* format is a string that contains text to be written to stdout
It can optionally contain embedded format specifiers that starts with a % character
These format specifiers get replaced by the values specified 
in subsequent additional arguments and formatted as requested.

* ... represents the variable number of additional arguments.

* The function returns the number of characters printed, or a negative value if an error occurs.

๐Ÿ“ Example

#include "ft_printf.h"

int main(void)
{
    ft_printf("Hello, %s!\n", "World");
    return 0;
}
This example prints "Hello, World!" to the console.

int main() {
	int num = 42;
	int *ptr = #
	ft_printf("The address of num is: %p\n", ptr);
	return 0;
}

In this example, ft_printf is called with a format string and a pointer argument. 
The format string contains a format specifier (%p), which corresponds to the pointer argument. 
The ft_printf function prints the string "The address of num is: 0x7fff5fbff710\n" (or similar) 
to the standard output, where "0x7fff5fbff710" is the address of num.

int main() {
	char *str = "Hello, world!";
	ft_printf("This is a string: %s\n", str);
	return 0;
}

In this example, ft_printf is called with a format string and a string argument. 
The format string contains a format specifier (%s), which corresponds to the string argument. 
The ft_printf function prints the string "This is a string: Hello, world!\n" to the standard output.

๐Ÿ“š Supported Format Specifiers
The ft_printf function supports the following format specifiers:

* %d or %i: Print an integer.
* %s: Print a string.
* %c: Print a character.
* %p: Print a pointer.
* %u: Print an unsigned integer.
* %x: Print an unsigned integer in hexadecimal (lowercase).
* %X: Print an unsigned integer in hexadecimal (uppercase).
* %%: Print a percent sign.

# Error Handling

If a function call within custom_printf fails, it returns -1 to indicate an error. 
Otherwise, it returns the total number of characters printed.

printf's People

Contributors

abdurahim-h avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.