ft_printf 🐋 🐢

Library that contains ft_printf, a function that will mimic the real printf, It will manage the following conversions [ cspdiuxX%]

ft_printf.c

#include "../includes/ft_printf.h"

int	ft_printf(const char *format, ...)
{
	t_info		*info;
	int			length;

	info = (t_info *)ft_memalloc(sizeof(t_info));
	va_start(info->arguments, format);
	info->format = format;
	while (*info->format)
	{
		while (*info->format && *info->format != '%')
		{
			ft_putchar(*info->format);
			info->total_length++;
			info->format++;
		}
		if (*info->format && *info->format == '%')
			ft_eval_input(info);
	}
	va_end(info->arguments);
	length = info->total_length;
	free(info);
	return (length);
}

ft_printf General Workflow 🔔

General Flow

See diagrams for each format specifier 🐙

🐾 General workflow 🐾

Format Specifiers

Format Specifiers

Context

[ flags ] [ width ] [ precision ]

Compilation

make all
gcc  ./tests/01_main_test_c.c libftprintf.a  -I ./include/

Note.: You can use "make re" to clean and build again

Debug Mode

First change your Makefile, adding -g3

@$(CC) -g3 $(CFLAGS) $(SRCS) -I$(INCLUDES)

Then, execute:

cd {$HOME}/42-silicon-valley-ft-printf
make all
gcc -g3 ./tests/01_main_test_c.c libftprintf.a
gcc -g3 ./tests/02_main_test_s.c libftprintf.a
gcc -g3 ./tests/03_main_test_di.c libftprintf.a
gcc -g3 ./tests/04_main_test_p.c libftprintf.a
gcc -g3 ./tests/05_main_test_x.c libftprintf.a
gcc -g3 ./tests/06_main_test_u.c libftprintf.a

lldb a.out
b main
run
gui

📺 Testers

🎆 Resources:

Norminette

Use and install this repository: Norminette

Linux

echo 'alias norminette="~/.norminette/norminette.rb"' >> ~/.profile
source ~/.profile

Run

norminette *.*

Valgrind

make all

gcc ./tests/01_main_test_c.c libftprintf.a  -I ./include/
gcc ./tests/02_main_test_s.c libftprintf.a  -I ./include/
gcc ./tests/03_main_test_di.c libftprintf.a  -I ./include/
gcc ./tests/04_main_test_p.c libftprintf.a  -I ./include/
gcc ./tests/05_main_test_x.c libftprintf.a  -I ./include/
gcc ./tests/06_main_test_u.c libftprintf.a  -I ./include/
gcc ./tests/07_main_test_prc.c libftprintf.a -I ./include/

valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-origins=yes --track-fds=yes ./a.out

Graded by Moulinette

alt text

ft_printf pdf new curriculum

Download from HERE