All the deets
Yesterday I messed around with printf to see how it works. It does several conversions
that we’ll have to implement, and for each conversions we still have to
parse different flags that modify the format (like %06.2f,%15.10s and %*d).
I’m structuring my code the following way:
I will verify that the number of arguments passed corresponds to the number ofI now know this is not necessary so I won’t bother. I might do it later if I feel like it.conversionsin the format string, and return an error (-1) otherwise.I’ll Iterate through the format string, writing each character to standard out until it reaches a
conversion.For each different
conversionI’ll write a “module” of functions that properly handles the formatting and printig of the output.
I’m avoiding memory allocation as much as I can. I also know that C doesn’t have modules; I’m using this term as an abstract concept to organize the functionalities of my code.
I chose to do it htis way because it is simple, I will allocate as little memory
as possible if any (avoid memory leaks), and it will make it easier for me to reuse
my libft functions.
Reading thorugh section 7.3 of The Ansi C Programming Language book, I came
across an example implementation of printf that roghly organizes it the same way.
My original intuition was doing it with splits and joins in the format string, but that would require some crazy checks between strings plus a ton of malloc and free calls.
I also learned about how to check types in C.
It’s a bit tricky, the most straight-forward way of doing it is using General,
but that’s not available on all compilers.
I sure hope we don’t have to check wheter the type of the conversion in doubt
matches the next variadic argument, if it should error out on ft_printf("% s ", 42);.
I also added github actions to my project, which automatically run the testers in a macos whenever I push the master. It’s an amazing feature github has to offer and I’m gonna use it more often:
Today I’ll start coding printf, starting with the makefile.
My biggest obstacle still is the netwhat retry time.