-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
51 lines (48 loc) · 1.48 KB
/
Copy pathft_substr.c
File metadata and controls
51 lines (48 loc) · 1.48 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpadenko <dpadenko@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/11 16:43:58 by dpadenko #+# #+# */
/* Updated: 2023/09/20 11:25:53 by dpadenko ### ########.fr */
/* */
/* ************************************************************************** */
//#include <stdio.h>
//#include <stdlib.h>
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *str;
size_t i;
if (ft_strlen(s) < start)
return (ft_strdup(""));
if (len > (ft_strlen(s) - start))
{
len = ft_strlen(s) - start;
}
str = malloc(len + 1);
if (str == NULL)
return (NULL);
i = 0;
while (i < len && s[start + i] != '\0')
{
str[i] = s[start + i];
i++;
}
str[len] = '\0';
return (str);
}
/*
int main(void)
{
char a[] = "0123456789";
char *substr = ft_substr(a, 9, 10);
if (substr != NULL)
{
printf("%s\n", substr);
free(substr);
}
}
*/