From: Dominik Kaiser Date: Sun, 10 Mar 2024 12:35:18 +0000 (+0100) Subject: Add everything X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=3c90d29fe5bf9ba6da090cd59c8c139d269f8bd4;p=42%2Flibft.git Add everything --- diff --git a/ft_atoi.o b/ft_atoi.o new file mode 100644 index 0000000..8280d24 Binary files /dev/null and b/ft_atoi.o differ diff --git a/ft_isalpha.o b/ft_isalpha.o new file mode 100644 index 0000000..b75a8da Binary files /dev/null and b/ft_isalpha.o differ diff --git a/ft_itoa.c b/ft_itoa.c new file mode 100644 index 0000000..401ba6a --- /dev/null +++ b/ft_itoa.c @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* int main() { */ +/* char* itoa = ft_itoa(0); */ +/* printf("%s\n", itoa); */ +/* } */ diff --git a/ft_putnbr_fd.c b/ft_putnbr_fd.c new file mode 100644 index 0000000..96f5f4b --- /dev/null +++ b/ft_putnbr_fd.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser 9) + putnbr_fd_rec(n / 10, fd); + write(fd, &c, 1); +} + +void ft_putnbr_fd(int n, int fd) +{ + if (n == -2147483648) + { + write(fd, "-2147483648", 11); + return ; + } + if (n < 0) + { + write(fd, "-", 1); + n *= -1; + } + putnbr_fd_rec(n, fd); +} diff --git a/ft_split.c b/ft_split.c new file mode 100644 index 0000000..e9ba9f9 --- /dev/null +++ b/ft_split.c @@ -0,0 +1,104 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* int main() */ +/* { */ +/* char s[] = " split this for me !"; */ +/* char **split = ft_split(s, ' '); */ + +/* if (split) { */ +/* while(*split) { */ +/* printf("%s\n", *split); */ +/* split++; */ +/* } */ +/* } */ +/* } */ diff --git a/ft_striteri.c b/ft_striteri.c new file mode 100644 index 0000000..e7c8b89 --- /dev/null +++ b/ft_striteri.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser + +static int get_len(char const *s) +{ + int i; + + i = 0; + while (s[i]) + i++; + return (i); +} + +static int copy_str(char *dst, const char *src) +{ + int i; + + i = 0; + while (src[i]) + { + dst[i] = src[i]; + i++; + } + return (i); +} + +char *ft_strjoin(char const *s1, char const *s2) +{ + int len; + char *result; + + len = get_len(s1) + get_len(s2); + result = malloc(len + 1); + if (result) + { + result[len] = '\0'; + len = copy_str(result, s1); + len = copy_str(result + len, s2); + return (result); + } + else + return (0); +} + +/* #include */ + +/* int main(void) */ +/* { */ +/* char s1[] = "Hello "; */ +/* char s2[] = "World"; */ + +/* printf("%s\n", ft_strjoin(s1, s2)); */ +/* } */ diff --git a/ft_strmapi.c b/ft_strmapi.c new file mode 100644 index 0000000..5d31408 --- /dev/null +++ b/ft_strmapi.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser */ +/* int main(){ */ +/* char str[] = "AAAAAAAA"; */ +/* printf("%s\n", ft_strmapi(str, func)); */ +/* } */ diff --git a/ft_strtrim.c b/ft_strtrim.c new file mode 100644 index 0000000..933987b --- /dev/null +++ b/ft_strtrim.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser + +static int is_in(char c, const char *str) +{ + while (*str) + { + if (c == *str) + return (1); + else + str++; + } + return (0); +} + +char *ft_strtrim(char const *s1, char const *set) +{ + int i; + char *start; + char *end; + char *result; + + start = (char *)s1; + while (is_in(*start, set)) + start++; + i = 0; + while (s1[i]) + i++; + end = (char *)s1 + i - 1; + while (end > start && is_in(*end, set)) + end--; + i = end - start + 1; + result = malloc(i + 1); + if (result) + { + result[i] = '\0'; + i = 0; + while (start <= end) + result[i++] = *(start++); + return (result); + } + return (0); +} + +/* #include */ + +/* int main(void) */ +/* { */ +/* char s1[] = " \t \t \t "; */ + +/* printf("%s\n", ft_strtrim(s1, " \t")); */ +/* } */ diff --git a/ft_substr.c b/ft_substr.c new file mode 100644 index 0000000..f5ee2aa --- /dev/null +++ b/ft_substr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + size_t i; + char *result; + + i = 0; + while (s[i]) + i++; + if (i - start < len) + len = (i - start); + if (start >= len) + len = 0; + result = malloc(len + 1); + if (result) + { + result[len] = '\0'; + i = 0; + while (i < len) + { + result[i] = s[i + start]; + i++; + } + } + return (result); +} + +/* #include */ +/* int main () */ +/* { */ +/* char s[] = "Hello there"; */ +/* char *substr = ft_substr(s, 25, 10); */ +/* printf("%s\n", substr); */ +/* } */