-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft_printf.c
63 lines (57 loc) · 2.04 KB
/
ft_printf.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cado-car <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/02 15:33:12 by cado-car #+# #+# */
/* Updated: 2021/08/20 19:46:46 by cado-car ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
/*
* LIBRARY
* #include <stdio.h>
* DESCRIPTION
* The functions in the printf() family produce output according to a format
* as described below. The functions printf() and vprintf() write output to
* stdout, the standard output stream.
* PARAMETERS
* #1. The string format in which the output will be printed.
* ... The variadic arguments passed to the format string's placeholders. In
* the vprintf() function, the variadic argument are already passed as a
* va_list type.
* RETURN VALUES
* Upon successful return, these functions return the number of characters
* printed (excluding the null byte used to end output to strings).
*/
int ft_printf(const char *format, ...)
{
va_list ap;
int len;
if (format == NULL)
return (0);
va_start(ap, format);
len = ft_vprintf(format, ap);
va_end(ap);
return (len);
}
int ft_vprintf(const char *format, va_list ap)
{
t_format *fmt;
int len;
fmt = ft_initialize_format(format, ap);
if (!fmt)
return (0);
while (fmt->format[fmt->i])
{
if (fmt->format[fmt->i] == '%')
ft_placeholder(fmt);
else
fmt->len += write(1, &fmt->format[fmt->i++], 1);
}
len = fmt->len;
free(fmt);
return (len);
}