-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_unknown_format.c
More file actions
43 lines (40 loc) · 1.59 KB
/
ft_unknown_format.c
File metadata and controls
43 lines (40 loc) · 1.59 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_unknown_format.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbalon-s <mbalon-s@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/24 23:36:50 by mbalon-s #+# #+# */
/* Updated: 2019/03/01 11:45:28 by mbalon-s ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdarg.h>
#include <stdlib.h>
#include "libftprintf.h"
size_t ft_unknown_format(char **pdst, t_specification spec)
{
char *str;
if (spec.ch == '\0')
{
*pdst = NULL;
return (0);
}
if (!spec.precision_set || 1 < spec.precision)
spec.precision = 1;
spec.minwidth = spec.minwidth < 1 ? spec.precision : spec.minwidth;
str = (char *)malloc(sizeof(char) * (spec.minwidth + 1));
if (str == NULL)
return (0);
if (!spec.force_zeroes || spec.align_left)
ft_memset(str, ' ', sizeof(char) * spec.minwidth);
else
ft_memset(str, '0', sizeof(char) * spec.minwidth);
str[spec.minwidth] = '\0';
if (spec.align_left)
str[0] = spec.ch;
else
str[spec.minwidth - 1] = spec.ch;
*pdst = str;
return (spec.minwidth);
}