Skip to content

Bruno0798/ft_printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ft_printf

ℹ️ Because ft_putnbr() and ft_putstr() aren’t enough

100/100

GitHub code size in bytes Code language count GitHub last commit


🗣️ About

This project consists of a static library that contains ft_printf - a function that mimics the real printf.
This functionality proves particularly advantageous when comparing it to its predecessor at 42, the system call write.
One of the significant advantages of ft_printf is its adaptability and reusability. It can be seamlessly integrated into future projects, streamlining the process of formatting and outputting data.

⚠️ Warning: Don't copy/paste code you don't understand: it's bad for you, and for the school.

How does libft work?

✨ For this project we were introduced to the concept of variadic functions ✨

The functionality of ft_printf is based on the concept of variadic functions, which allows it to handle a variable number of arguments. This project involves creating a function that emulates the behavior of the widely-used printf function in the C language.

In essence, ft_printf takes a string as its primary argument, and this string can contain placeholders, such as %c for characters or %s for strings. The actual values to be substituted into these placeholders are passed as additional arguments to the function. The function's return value is the number of characters printed, or -1 in the case of an error.

To implement a function like this, it needs to be variadic, meaning it accepts a variable number of arguments. This is achieved through the use of the <stdarg.h> header and specific parameters like va_arg to access the arguments in order, va_start to begin using the argument list, and va_end to conclude it.

For each type of conversion specified in the project requirements, there's a corresponding function within ft_printf that converts the argument and returns the number of bytes written:

%c print a single character.

%s print a string of characters.

%p The void * pointer argument is printed in hexadecimal.

%d print a decimal (base 10) number.

%i print an integer in base 10.

%u print an unsigned decimal (base 10) number.

%x print a number in hexadecimal (base 16).

%% print a percent sign.

NORMINETTE

At 42 School, aligning to the 42 Norms, the school's coding standard, is a fundamental expectation for all projects.

About

Recode printf funtion.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published