Skip to content

This project consists of coding a library that contains a simplified version of the printf function.

License

Notifications You must be signed in to change notification settings

mendes-jv/ft-printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ft_printf: You will recode printf and learn how to use variadic arguments

Norminette and Build 42 São Paulo License Code size in bytes Top language Last commit

Index:

Grade:

Ft Printf

jovicto2's 42 Ft_Printf Score

Description:

Ft_Printf is the third project at 42. In short, this project consists of coding a library that contains a simplified version of the printf function. It's an extremely useful function that can be used in following school's projects.

The project:

Specifiers

Format Specifier Description
% % followed by another % character writes % to the screen.
c writes a single character.
s writes a character string.
p writes an implementation-defined character sequence defining a pointer address.
d or i writes a signed integer to decimal representation.
u writes an unsigned integer to decimal representation.
x or X writes an unsigned integer to hexadecimal representation.
o writes an unsigned integer to octal representation.
b writes an unsigned integer to binary representation.
f (mandatory only) writes a float number.

Flags (bonus only)

Flag Description
- Left justify the result within the field. By default it is right justified.
+ Forces to precede the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a sign.
(space) If there is no sign, a space is attached to the beginning of the result.
# Used with x or X specifiers the value is preceded with 0x or 0X respectively for values different than zero.
0 Leading zeros are used to pad the numbers instead of space.

Width

Value Description
(integer) Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.

Precision

Value Description
.(integer) For integer specifiers (d, i, u, x, X, o, b, f) − precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer. A precision of 0 means that no character is written for the value 0. For s − this is the maximum number of characters to be printed. By default all characters are printed until the ending null character is encountered. For c type − it has no effect. When no precision is specified, the default is 1. If the period is specified without an explicit value for precision, 0 is assumed.

How to execute:


⚠️ Warning ⚠️

❗ This project uses an old libft version as a dependency. The most recent version of libft has ft_printf added in its source code.


First, clone this repository and cd into it:

git clone https://github.com/mendes-jv/ft-printf && cd ft-printf

To use the function in your code, simply include its header:

#include "ft_printf.h"

Or, if you want to test the bonus version of the functions (it's the same functions but with flags implementation):

#include "ft_printf_bonus.h"

Compile the library with:

make

Or, if you want to compile the bonus version (recommended):

make bonus

Now, when compiling your code, add the source files and the required flag:

[gcc | cc | clang] [flags] your_main.c src/mandatory/ft_printf.c libftprintf.a && ./a.out

Or, if you want to compile the bonus files:

[gcc | cc | clang] [flags] your_main.c src/bonus/ft_printf_bonus.c libftprintf.a && ./a.out

You can test the functions with the files provided by me in this respository using:

gcc -Wall -Werror -Wextra  main.c src/mandatory/ft_printf.c libftprintf.a && ./a.out

Or

gcc -Wall -Werror -Wextra  main.c src/bonus/ft_printf_bonus.c libftprintf.a && ./a.out