-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
56 lines (50 loc) · 1.8 KB
/
ft_substr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: evdos-sa <evdos-sa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/02 16:24:05 by evdos-sa #+# #+# */
/* Updated: 2022/11/20 13:49:17 by evdos-sa ### ########.fr */
/* */
/* ************************************************************************** */
/* ************************************************************************** */
/* Aloca (com malloc(3)) e retorna uma substring da string 's'.
A substring começa no índice 'start' e é de tamanho máximo 'len'.*/
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
char *sub;
sub = malloc((sizeof(char) * len) + 1);
if (!(sub))
return (NULL);
i = 0;
if (s)
{
while (i + start < ft_strlen(s) && i < len)
{
sub[i] = s[i + start];
i++;
}
}
sub[i] = '\0';
return (sub);
}
/*
int main()
{
char *str;
Everton Mota:
s = A string a partir da qual criar a substring.
7:
stsrt = O índice inicial da substring na string.
4:
len = O comprimento máximo da substring.
str = ft_substr("PORTO", 2, 2);
printf("%s", str);
return (0);
}
*/