/ft_printf

Simplified version of the printf function.

Primary LanguageC

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

The printf function is one of the most known and used in the C language to give an output. It takes a string as an argument, this string may contain some placeholders (like %c for characters or %s for strings) whose original values are passed as arguments. The ft_printf has variable arguments, the only one being mandatory is the string that will be printed, otherwise it depends on how many placeholders are passed in this string. The function's return is the number of characters printed or -1 for error.

To create with a function like this, it must be a variadic function (with variable number of arguments), which is possible to achieve using the header <stdarg.h> and parameters like va_arg for the list arguments in order of occurrence or va_start and va_end to start and end the use of the argument list. For each conversion required by the subject, there's a function that converts the argument and returns the numer of bytes writed:

%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.