-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstr_append_char.c
35 lines (31 loc) · 1.29 KB
/
str_append_char.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_append_char.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alischyn <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 18:02:15 by alischyn #+# #+# */
/* Updated: 2017/03/22 18:15:59 by alischyn ### ########.fr */
/* */
/* ************************************************************************** */
#include "str.h"
int str_append_char(t_str *str, char chr)
{
if (str->length + 1 > str->capacity)
str_realloc(str, 1);
str->string[str->length++] = chr;
return (1);
}
int str_append_char_n(t_str *str, char chr, int count)
{
int ret;
if (count <= 0)
return (0);
ret = count;
if (str->length + count > str->capacity)
str_realloc(str, count);
while (count--)
str->string[str->length++] = chr;
return (ret);
}