-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_printf_s.c
42 lines (36 loc) · 934 Bytes
/
my_printf_s.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
/*
** EPITECH PROJECT, 2023
** my_printf_s
** File description:
** Placeholder
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "include/my.h"
char *getargs_l(va_list list, params_t params)
{
return 0;
}
char *getargs_c(va_list list, params_t params)
{
char *str = va_arg(list, char *);
int precision;
char *arg;
precision = (params.precision != 0) ? *params.precision : my_strlen(str);
arg = malloc(sizeof(char) * (precision + 1));
for (int i = 0; i < precision; i++)
arg[i] = str[i];
arg[precision] = '\0';
return arg;
}
int my_printf_s(va_list list, params_t *params)
{
int count = 0;
char *(*getargs[2])(va_list, params_t) = {&getargs_c, &getargs_l};
to_print_t to_print = initialize_to_print();
to_print.arg = getargs[params->length](list, *params);
do_flags(&to_print, *params);
count += write_struct(to_print);
return count;
}