tgrekov-ft_printf
HIVE printf Feb 2024
Loading...
Searching...
No Matches
repeat_str_n.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* repeat_str_n.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/12/20 21:26:03 by tgrekov #+# #+# */
9/* Updated: 2024/02/13 06:25:59 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include "../../../libft/libft.h"
21
22static int _repeat_str_n(const char *str, int n, int strlen, int fd)
23{
24 int res;
25 int res2;
26
27 res = 0;
28 if (n > strlen)
29 {
30 res = _repeat_str_n(str, n - strlen, strlen, fd);
31 if (res == -1)
32 return (-1);
33 n = strlen;
34 }
35 res2 = write(fd, str, n);
36 if (res2 == -1)
37 return (-1);
38 return (res + res2);
39}
40
50int repeat_str_n(const char *str, int n, int fd)
51{
52 if (n < 1)
53 return (0);
54 return (_repeat_str_n(str, n, ft_strlen(str), fd));
55}
size_t ft_strlen(const char *str)
Get length of str.
Definition ft_strlen.c:28
int repeat_str_n(const char *str, int n, int fd)
Write exactly n characters from str on descriptor fd. Repeats string if ft_strlen(str) is greater tha...