-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_prec.c
More file actions
51 lines (44 loc) · 1.51 KB
/
ft_printf_prec.c
File metadata and controls
51 lines (44 loc) · 1.51 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_prec.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpeters <tpeters@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/04 13:40:32 by tpeters #+# #+# */
/* Updated: 2022/05/04 14:53:38 by tpeters ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int put_str_prec(char *tmp, int precision)
{
int count;
count = 0;
while ((precision >= 0 && count < precision && tmp[count])
|| (precision < 0 && tmp[count]))
{
ft_putchar_fd(tmp[count], 1);
count++;
}
return (count);
}
int num_len(char *in)
{
while (*in && !ft_isdigit(*in))
in++;
return (ft_strlen(in));
}
int str_prec(char *tmp, int precision)
{
int a;
a = ft_strlen(tmp);
if (a > precision && precision >= 0)
return (precision);
return (a);
}
int int_prec(char *tmp, int precision)
{
if (num_len(tmp) < precision)
return (ft_strlen(tmp) - num_len(tmp) + precision);
return (ft_strlen(tmp));
}