-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprint_s.c
More file actions
134 lines (128 loc) · 4.17 KB
/
print_s.c
File metadata and controls
134 lines (128 loc) · 4.17 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_s.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hiroshiusui <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/31 02:38:27 by hiroshius #+# #+# */
/* Updated: 2018/01/31 02:38:28 by hiroshius ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
/*
** *******************************Mandatory Part*******************************
** Types of conversions:
**
** s S p d D i o O u U x X c C
** s: Print characters from the string until a '\0' or the number of
** characters given by the precision
**
** S: Equivalent of "%ls"
**
** p: Pointer
**
** d: Signed decimal integer
**
** D: Equivalent of "%ld"
**
** i: Equivalent of 'd'
**
** o: Unsigned octal number (without a leading zero)
**
** u: Unsigned decimal number
**
** U: Equivalent of "%lu"
**
** x: Unsigned hexadecimal number (without a leading 0x), using abcdef
** for 10, ..., 15.
**
** X: Unsigned hexadecimal number (without a leading 0X), using ABCDEF
** for 10, ..., 15.
**
** c: Single character
**
** C: Equivalent of "%lc"
**
** Length modifiers:
** Modifier d, i o, u, x, X n
** hh signed char unsigned char signed char *
** h short unsigned short short *
** l (ell) long unsigned long long *
** ll (ell ell) long long unsigned long long long long *
** j intmax_t uintmax_t intmax_t *
** z (see note) size_t (see note)
**
** Flags:
** #: A "#" character sepcifies that the value should be printed in
** "alternate" form.
** This option has no effect on "b, c, d, s," and "u" formats.
** For the o formats, the precision of the number increases to make the first
** character of the outputted string to be zero.
** For the x/X format, a non-zero string has the string 0x/0X prepended to it.
** For "a, A, e, E, f, F, g, and G formats", the result always has a decimal.
** For "g and G" formats, trailing zeros are not removed from the result as
** they usually would be.
** 0: A "0" character indicates that zero-padding should be used rather than
** blank padding. A "-" overrides a "0" if both are used. If a numeric
** conversion is given (d, i, o, u, i, x, and X), then the '0' flag is ignored.
** -: A "-" sign specifies left adjusment of the output.
** +: A "+" character specifies that there should always be a sign placed
** before the number when using signed formats.
** _: A space specifies that a blank should be left before before a positive
** number for a signed format. A "+" overrides a space if both are used.
*/
void print_s_upper(t_bag *bag, va_list args, int *i)
{
wchar_t *str;
int x;
int length;
char *new;
str = (wchar_t *)va_arg(args, void *);
length = 0;
new = "";
if (str && !(x = 0))
{
while (str[x++])
length++;
while (*str)
new = ft_strjoin(new, stringerize((char)(*str++)));
if (bag->precision < length && bag->period)
new = cut_right(new, length - bag->precision);
if (!bag->minus)
new = pad_left(new, bag->width, ' ');
else
new = pad_right(new, bag->width, ' ');
*i += ft_strlen(new);
ft_putstr(new);
}
else
(*i) += ft_printf("(null)");
}
void print_s(t_bag *bag, va_list args, int *i)
{
char *str;
int x;
int length;
char *new;
str = (char *)va_arg(args, void *);
length = 0;
new = "";
if (str && !(x = 0))
{
while (str[x++])
length++;
while (*str)
new = ft_strjoin(new, stringerize(*str++));
if (bag->precision < length && bag->period)
new = cut_right(new, length - bag->precision);
if (!bag->minus)
new = pad_left(new, bag->width, ' ');
else
new = pad_right(new, bag->width, ' ');
*i += ft_strlen(new);
ft_putstr(new);
}
else
(*i) += ft_printf("(null)");
}