1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
ft_printf
================
Description
----------
This is a custom implementation of printf() glibc.
I wrote this implementation to carry on learning C and understand what printf
does, to an extend.
This implementation is concerned with the following specifiers only: c, s,
i, d, u, x, X, p.
Instructions
-----------
To clone the repository of this library run:
$ git clone https://git.yctct.com/ft_printf
$ cd ft_printf
To compile the library run:
$ make
To recompile the library run:
$ make re
To delete all object files run:
$ make clean
To delete all object files and libft.a run:
$ make fclean
Then to use the library, libftprintf.a, with a programme, say main.c, run:
$ cc main.c libftprintf.a
and prepend each of the C files with:
#include "path/to/ft_printf.h"
Implementation choice
---------------------
ft_printf.c parses the string for the specifier. When it finds a specifier, a
helper function check the character following the specifier against conversion
specifier, when the condition is true (i.e. the char following the specifier is
a conversion specifier, then the argument pointer is passed to a function that
will convert the argument according to the conversion specifier.
Possible improvements:
- I could probably merge both functions converting decimal to hexadecimal into
a single function.
- At the end of my implement, I added a function, ft_checkpadd.c to check
whether the address a pointer is pointing to is zero. I could try to
integrate that function elsewhere.
- deal with edge case when % is the last char of a string
Some edge cases this implementation takes into account:
- specifier followed by a non-conversation specifier character e.g. %t
- print(0);
- print ("");
Relevant projects
-----------------
- [add URL to printf test]
Resources
---------
- Oceano's tutorials on variadic functions and "mini printf"
- man stdarg for variadic functions.
- man limits.h for INT_MAX, etc.
- man 3 printf
License
-------
Copyright (C) 2026 yctct
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
See the file COPYING.
|