remis quelques headers et a la norme
This commit is contained in:
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:13:30 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 17:06:48 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** delete and free an element of the list and all the followings
|
||||
*/
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:14:03 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 16:56:40 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/11/25 14:35:53 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:14:11 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/29 16:23:54 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/12/01 16:03:40 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -76,10 +76,10 @@
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!f)
|
||||
return;
|
||||
return ;
|
||||
while (lst)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:14:49 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 16:42:21 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/11/28 16:43:18 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:15:42 by hulamy #+# #+# */
|
||||
/* Updated: 2019/12/01 16:02:13 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** iterate trhough linked list and apply to each element a function f
|
||||
** if necessary the function del is used to delete an element
|
||||
@@ -109,7 +121,9 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
t_list *new;
|
||||
t_list *tmp;
|
||||
|
||||
if(!(tmp = ft_lstnew(f(lst->content))))
|
||||
if (!lst)
|
||||
return (NULL);
|
||||
if (!(tmp = ft_lstnew(f(lst->content))))
|
||||
{
|
||||
del(tmp->content);
|
||||
free(tmp);
|
||||
@@ -119,7 +133,7 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
while (lst->next)
|
||||
{
|
||||
lst = lst->next;
|
||||
if(!(tmp->next = ft_lstnew(f(lst->content))))
|
||||
if (!(tmp->next = ft_lstnew(f(lst->content))))
|
||||
{
|
||||
del(tmp->next->content);
|
||||
free(tmp->next);
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
** 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 "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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:16 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 15:08:38 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/12/01 14:54:14 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -22,13 +22,7 @@
|
||||
** int main(int ac, char **av)
|
||||
** {
|
||||
** if (ac == 4)
|
||||
** {
|
||||
** printf("%s\n", ft_memcpy(av[1], av[2], atoi(av[3])));
|
||||
** }
|
||||
** else
|
||||
** {
|
||||
** printf("%s\n", ft_memcpy("troubadour", "bravo", 4));
|
||||
** }
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:25 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 14:57:58 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/11/28 15:04:39 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -14,6 +14,37 @@
|
||||
** 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)
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:56:54 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 16:24:25 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/11/25 13:56:55 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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'
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:00:13 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/27 21:35:21 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/12/01 16:01:20 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -60,9 +60,7 @@
|
||||
** {
|
||||
** i = 0;
|
||||
** s = av[1];
|
||||
** // s = "lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse";
|
||||
** c = av[2][0];
|
||||
** // c = ' ';
|
||||
** str = ft_split(s, c);
|
||||
** while (str[i])
|
||||
** printf("%s\n", str[i++]);
|
||||
@@ -5,8 +5,8 @@
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:01:58 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/28 16:32:34 by hulamy ### ########.fr */
|
||||
/* Created: 2019/12/01 16:00:10 by hulamy #+# #+# */
|
||||
/* Updated: 2019/12/01 16:00:12 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -19,14 +19,55 @@
|
||||
**
|
||||
** char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
**
|
||||
** 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);
|
||||
** }
|
||||
**
|
||||
** 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);
|
||||
** }
|
||||
**
|
||||
** size_t ft_strlen(const char *str)
|
||||
** {
|
||||
** size_t i;
|
||||
**
|
||||
** i = 0;
|
||||
** while (str[i])
|
||||
** i++;
|
||||
** return (i);
|
||||
** }
|
||||
**
|
||||
** int main(int ac, char **av)
|
||||
** {
|
||||
** char *str;
|
||||
**
|
||||
** if (ac != 4)
|
||||
** return (0);
|
||||
** str = ft_substr(av[1], atoi(av[2]), atoi(av[3]));
|
||||
** printf("%s\n",str);
|
||||
** str = "";
|
||||
** size_t size = 0;
|
||||
** char *ret = ft_substr(str, 5, size);
|
||||
** if (!ft_strncmp(ret, str + 5, size))
|
||||
** printf("gloups\n");
|
||||
** free(ret);
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
Reference in New Issue
Block a user