-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibft_functions_2.c
70 lines (62 loc) · 1.73 KB
/
libft_functions_2.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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft_functions_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfreitas <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/21 13:30:29 by jfreitas #+# #+# */
/* Updated: 2020/01/28 11:31:50 by jfreitas ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *ft_strncpy(char *dest, char const *src, size_t len)
{
size_t i;
i = 0;
while (src[i] != '\0' && i < len)
{
dest[i] = src[i];
i++;
}
while (i < len)
{
dest[i] = '\0';
i++;
}
return (dest);
}
char *ft_strcpy(char *dest, char const *src)
{
int i;
i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
int ft_strcmp(char const *s1, char const *s2)
{
while ((*s1 && *s2) && *s1 == *s2)
{
s1++;
s2++;
}
if (*s1 == *s2)
return (0);
else
return (*((unsigned char*)s1) - *((unsigned char*)s2));
}
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *fresh_sub_str;
fresh_sub_str = ft_strnew(len);
if (fresh_sub_str == NULL || s == NULL)
return (NULL);
if (start < ft_strlen(s))
ft_strncpy(fresh_sub_str, &s[start], len);
return (fresh_sub_str);
}