makefile a la norme
This commit is contained in:
39
srcs/part1/ft_atoi.c
Normal file
39
srcs/part1/ft_atoi.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:54:29 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:54:35 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
long long nbr;
|
||||
int i;
|
||||
int n;
|
||||
|
||||
i = 0;
|
||||
n = 1;
|
||||
nbr = 0;
|
||||
while ((str[i] == 32) || (str[i] > 8 && str[i] < 14))
|
||||
i++;
|
||||
if (str[i] == '-')
|
||||
n = -1;
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
i++;
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
if ((nbr >= 922337203685477580
|
||||
&& ((str[i] > 8 && n < 0) || (str[i] > 7 && n > 0))))
|
||||
return ((n > 0) ? -1 : 0);
|
||||
else
|
||||
nbr = nbr * 10 + (str[i++] - '0');
|
||||
}
|
||||
return (nbr * n);
|
||||
}
|
||||
27
srcs/part1/ft_bzero.c
Normal file
27
srcs/part1/ft_bzero.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:54:43 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:54:44 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *ptr;
|
||||
|
||||
if (n)
|
||||
{
|
||||
ptr = (unsigned char *)s;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
ptr[i++] = '\0';
|
||||
}
|
||||
}
|
||||
64
srcs/part1/ft_calloc.c
Normal file
64
srcs/part1/ft_calloc.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:54:53 by hulamy #+# #+# */
|
||||
/* Updated: 2019/12/01 16:04:12 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** exemple allocation for 5 integers with malloc then calloc :
|
||||
** a = (int *)malloc(5 * sizeof(int)); //5*4bytes = 20 bytes
|
||||
** free(a);
|
||||
** a = (int *)calloc(5, sizeof(int));
|
||||
**
|
||||
** allocate count * size byte of memory and
|
||||
** return a pointer to the allocated memory
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** void ft_bzero(void *s, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** unsigned char *ptr;
|
||||
**
|
||||
** if (n)
|
||||
** {
|
||||
** ptr = (unsigned char *)s;
|
||||
** i = 0;
|
||||
** while (i < n)
|
||||
** ptr[i++] = '\0';
|
||||
** }
|
||||
** }
|
||||
**
|
||||
** void *ft_calloc(size_t count, size_t size);
|
||||
**
|
||||
** int main(void)
|
||||
** {
|
||||
** void *str;
|
||||
**
|
||||
** str = ft_calloc(0, 0);
|
||||
** if (str == ((void *)0))
|
||||
** printf("failed\n");
|
||||
** free(str);
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t count, size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
if (!(tmp = malloc(count * size)))
|
||||
return (NULL);
|
||||
ft_bzero(tmp, count * size);
|
||||
return (tmp);
|
||||
}
|
||||
18
srcs/part1/ft_isalnum.c
Normal file
18
srcs/part1/ft_isalnum.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:05 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:06 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
return (ft_isalpha(c) || ft_isdigit(c));
|
||||
}
|
||||
18
srcs/part1/ft_isalpha.c
Normal file
18
srcs/part1/ft_isalpha.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:15 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:17 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
|
||||
}
|
||||
18
srcs/part1/ft_isascii.c
Normal file
18
srcs/part1/ft_isascii.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:24 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:25 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
return (c >= 0 && c <= 127);
|
||||
}
|
||||
18
srcs/part1/ft_isdigit.c
Normal file
18
srcs/part1/ft_isdigit.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:32 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:33 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
18
srcs/part1/ft_isprint.c
Normal file
18
srcs/part1/ft_isprint.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:43 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:44 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
return (c >= 32 && c < 127);
|
||||
}
|
||||
36
srcs/part1/ft_memccpy.c
Normal file
36
srcs/part1/ft_memccpy.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memccpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 15:24:51 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 15:25:09 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy string until character is found and place cursor in dst
|
||||
** after last byte copied
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
|
||||
{
|
||||
unsigned char *dest;
|
||||
unsigned char *sourc;
|
||||
size_t i;
|
||||
|
||||
i = -1;
|
||||
dest = (unsigned char *)dst;
|
||||
sourc = (unsigned char *)src;
|
||||
while (++i < n)
|
||||
{
|
||||
dest[i] = sourc[i];
|
||||
if (sourc[i] == (unsigned char)c)
|
||||
return (dst + i + 1);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
30
srcs/part1/ft_memchr.c
Normal file
30
srcs/part1/ft_memchr.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:55:51 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:55:54 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** locate character in string and return its position
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *sbis;
|
||||
size_t i;
|
||||
|
||||
sbis = (unsigned char *)s;
|
||||
i = -1;
|
||||
while (++i < n)
|
||||
if (sbis[i] == (unsigned char)c)
|
||||
return ((void *)sbis + i);
|
||||
return (NULL);
|
||||
}
|
||||
32
srcs/part1/ft_memcmp.c
Normal file
32
srcs/part1/ft_memcmp.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:05 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:56:07 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** compare two bytes strings (doesnt recognize a null terminated string)
|
||||
** and return value of difference between first two different character
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
unsigned char *frst;
|
||||
unsigned char *scnd;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
frst = (unsigned char *)s1;
|
||||
scnd = (unsigned char *)s2;
|
||||
while (i < n && frst[i] == scnd[i])
|
||||
i++;
|
||||
return ((i == n) ? 0 : frst[i] - scnd[i]);
|
||||
}
|
||||
46
srcs/part1/ft_memcpy.c
Normal file
46
srcs/part1/ft_memcpy.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:16 by hulamy #+# #+# */
|
||||
/* Updated: 2019/12/01 14:54:14 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy n characters from src to dst and return dst
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n);
|
||||
**
|
||||
** int main(int ac, char **av)
|
||||
** {
|
||||
** if (ac == 4)
|
||||
** printf("%s\n", ft_memcpy(av[1], av[2], atoi(av[3])));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
int i;
|
||||
char *ptr;
|
||||
char *ptr2;
|
||||
|
||||
i = -1;
|
||||
ptr = (char *)dst;
|
||||
ptr2 = (char *)src;
|
||||
if (dst == src)
|
||||
return (dst);
|
||||
while (++i < (int)n)
|
||||
ptr[i] = ptr2[i];
|
||||
return (dst);
|
||||
}
|
||||
68
srcs/part1/ft_memmove.c
Normal file
68
srcs/part1/ft_memmove.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:25 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 15:04:39 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy n characters from src to dst in a non destructive way and return dst
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** size_t ft_strlen(const char *str)
|
||||
** {
|
||||
** size_t i;
|
||||
**
|
||||
** i = 0;
|
||||
** while (str[i])
|
||||
** i++;
|
||||
** return (i);
|
||||
** }
|
||||
**
|
||||
** void *ft_memmove(void *dst, const void *src, size_t len);
|
||||
**
|
||||
** //int main(int ac, char **av)
|
||||
** int main(void)
|
||||
** {
|
||||
** char *src = "this is a good nyancat !\r\n";
|
||||
** char dst[0xF0];
|
||||
** int size = strlen(src);
|
||||
**
|
||||
** // if (ac == 4)
|
||||
** // printf("%s\n", ft_memmove(av[1], av[2], atoi(av[3])));
|
||||
**
|
||||
** ft_memmove(dst, src, size);
|
||||
** printf("%s", dst);
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dst, const void *src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
char *cpsrc;
|
||||
char *cpdst;
|
||||
|
||||
i = -1;
|
||||
cpsrc = (char *)src;
|
||||
cpdst = (char *)dst;
|
||||
if (dst == src)
|
||||
return (dst);
|
||||
if (cpsrc < cpdst)
|
||||
while (len--)
|
||||
cpdst[len] = cpsrc[len];
|
||||
else
|
||||
while (++i < len)
|
||||
cpdst[i] = cpsrc[i];
|
||||
return (dst);
|
||||
}
|
||||
29
srcs/part1/ft_memset.c
Normal file
29
srcs/part1/ft_memset.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:37 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:56:38 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy n time a character in a string and return the string
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len)
|
||||
{
|
||||
char *ptr;
|
||||
size_t i;
|
||||
|
||||
ptr = (char *)b;
|
||||
i = 0;
|
||||
while (i < len)
|
||||
ptr[i++] = c;
|
||||
return (b);
|
||||
}
|
||||
33
srcs/part1/ft_strchr.c
Normal file
33
srcs/part1/ft_strchr.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:46 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:56:47 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** locate the first occurence of character c in string s
|
||||
** and return pointer to its location
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = -1;
|
||||
while (s[i])
|
||||
i++;
|
||||
while (++j < i + 1)
|
||||
if (s[j] == c)
|
||||
return ((char *)s + j);
|
||||
return (NULL);
|
||||
}
|
||||
32
srcs/part1/ft_strdup.c
Normal file
32
srcs/part1/ft_strdup.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:54 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:56:55 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** save a copy of string src by allocating memory and return pointer to copy
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *src)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
while (src[i] != '\0')
|
||||
i++;
|
||||
if (!(str = (char*)malloc(sizeof(*str) * (i + 1))))
|
||||
return (NULL);
|
||||
while (i-- >= 0)
|
||||
str[i + 1] = src[i + 1];
|
||||
return (str);
|
||||
}
|
||||
108
srcs/part1/ft_strlcat.c
Normal file
108
srcs/part1/ft_strlcat.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:57:02 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 14:23:18 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** append src to sized dest and return size of final dest
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** size_t ft_strlcat(char *dest, const char *src, size_t size);
|
||||
**
|
||||
** size_t ft_strlcat2(char *dest, char *src, size_t size);
|
||||
**
|
||||
** int ft_strlen(char *str)
|
||||
** {
|
||||
** int i;
|
||||
**
|
||||
** i = 0;
|
||||
** while (str[i])
|
||||
** i++;
|
||||
** return (i);
|
||||
** }
|
||||
**
|
||||
** int main(int ac, char **av)
|
||||
** {
|
||||
** char tmp1[100];
|
||||
** char tmp2[100];
|
||||
** int i;
|
||||
**
|
||||
** i = atoi(av[3]);
|
||||
** strcpy(tmp1, av[1]);
|
||||
** strcpy(tmp2, av[2]);
|
||||
**
|
||||
** if (ac == 4)
|
||||
** {
|
||||
** printf("----strlcat: %zu - %s - %s\n", strlcat(tmp1, tmp2, i),
|
||||
** tmp1, tmp2);
|
||||
**
|
||||
** strcpy(tmp1, av[1]);
|
||||
** strcpy(tmp2, av[2]);
|
||||
**
|
||||
** printf("-ft_strlcat: %zu - %s - %s\n", ft_strlcat(tmp1, tmp2, i),
|
||||
** tmp1, tmp2);
|
||||
**
|
||||
** strcpy(tmp1, av[1]);
|
||||
** strcpy(tmp2, av[2]);
|
||||
**
|
||||
** printf("ft_strlcat2: %zu - %s - %s\n", ft_strlcat2(tmp1, tmp2, i),
|
||||
** tmp1, tmp2);
|
||||
** }
|
||||
** }
|
||||
**
|
||||
** size_t ft_strlcat2(char *dest, char *src, size_t size)
|
||||
** {
|
||||
** size_t i;
|
||||
** size_t dest_length;
|
||||
** size_t src_length;
|
||||
**
|
||||
** i = 0;
|
||||
** dest_length = ft_strlen(dest);
|
||||
** src_length = ft_strlen(src);
|
||||
** if (size > dest_length + 1)
|
||||
** {
|
||||
** while (i < (size - dest_length - 1))
|
||||
** {
|
||||
** dest[i + dest_length] = src[i];
|
||||
** i++;
|
||||
** }
|
||||
** dest[dest_length + i] = '\0';
|
||||
** }
|
||||
** if (size >= dest_length)
|
||||
** return (dest_length + src_length);
|
||||
** return (src_length + size);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (dest[i] && i < size)
|
||||
i++;
|
||||
while (src[j])
|
||||
{
|
||||
if (j + i < size - 1 && size)
|
||||
{
|
||||
dest[i + j] = src[j];
|
||||
dest[i + j + 1] = '\0';
|
||||
}
|
||||
j++;
|
||||
}
|
||||
return (i + j);
|
||||
}
|
||||
66
srcs/part1/ft_strlcpy.c
Normal file
66
srcs/part1/ft_strlcpy.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:57:19 by hulamy #+# #+# */
|
||||
/* Updated: 2019/12/01 16:12:57 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy size - 1 length of src into dest,
|
||||
** terminate it with a '\0'
|
||||
** and return size of src
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** size_t ft_strlcpy(char *dest, const char *src, size_t size);
|
||||
**
|
||||
** int main(int argc, char **argv)
|
||||
** {
|
||||
** char str[100];
|
||||
** int i;
|
||||
** unsigned int u;
|
||||
** unsigned int v;
|
||||
**
|
||||
** i = atoi(argv[3]);
|
||||
** strcpy(str, argv[2]);
|
||||
** if (argc > 3)
|
||||
** {
|
||||
** u = strlcpy(argv[2], argv[1], i);
|
||||
** printf("strlcpy : %s - %s - %d",argv[1], argv[2], i);
|
||||
** printf(" - return:%d\n",u);
|
||||
** strcpy(argv[2], str);
|
||||
** printf("(re-init : %s - %s - %d)\n",argv[1], argv[2], i);
|
||||
** v = ft_strlcpy(argv[2], argv[1], i);
|
||||
** printf("ft_strlcpy: %s - %s - %d",argv[1], argv[2], i);
|
||||
** printf(" - return:%d\n",v);
|
||||
** }
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (src[i] != '\0')
|
||||
{
|
||||
if (i + 1 < size)
|
||||
dest[i] = src[j++];
|
||||
i++;
|
||||
}
|
||||
if (size > 0)
|
||||
dest[j] = '\0';
|
||||
return (i);
|
||||
}
|
||||
27
srcs/part1/ft_strlen.c
Normal file
27
srcs/part1/ft_strlen.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:57:48 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:57:49 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** return length of of string
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *str)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
32
srcs/part1/ft_strncmp.c
Normal file
32
srcs/part1/ft_strncmp.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:57:59 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:58:00 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** compare size first character of two null terminated strings
|
||||
** and return value of difference between first two different character
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
int res;
|
||||
|
||||
i = 0;
|
||||
res = 0;
|
||||
while (s1[i] && s1[i] == s2[i] && i < n - 1)
|
||||
i++;
|
||||
if (n != 0)
|
||||
res = (unsigned char)s1[i] - (unsigned char)s2[i];
|
||||
return (res);
|
||||
}
|
||||
42
srcs/part1/ft_strnstr.c
Normal file
42
srcs/part1/ft_strnstr.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:58:10 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:58:11 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** locate the first occurence of the string little in len first characters
|
||||
** of big and return a pointer to this occurence if found
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
j = 0;
|
||||
i = 0;
|
||||
if (!ft_strlen(little))
|
||||
return ((char *)big);
|
||||
while (i == 0 && j <= len)
|
||||
{
|
||||
while (little[i] == big[j + i] && little[i] && j + i <= len)
|
||||
i++;
|
||||
if (little[i])
|
||||
{
|
||||
j++;
|
||||
if (!big[j] || j >= len)
|
||||
return (0);
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
return ((char *)big + j);
|
||||
}
|
||||
32
srcs/part1/ft_strrchr.c
Normal file
32
srcs/part1/ft_strrchr.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:58:20 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:58:21 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** locate the last occurence of character c in string s
|
||||
** and return pointer to its location
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s[i])
|
||||
i++;
|
||||
i++;
|
||||
while (i--)
|
||||
if (s[i] == c)
|
||||
return ((char *)s + i);
|
||||
return (NULL);
|
||||
}
|
||||
20
srcs/part1/ft_tolower.c
Normal file
20
srcs/part1/ft_tolower.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:58:30 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:58:32 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (c + 32);
|
||||
return (c);
|
||||
}
|
||||
20
srcs/part1/ft_toupper.c
Normal file
20
srcs/part1/ft_toupper.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:58:39 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:58:43 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c - 32);
|
||||
return (c);
|
||||
}
|
||||
Reference in New Issue
Block a user