mise a niveau des dernieres modifications
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/11/25 13:55:51 by hulamy #+# #+# */
|
/* Created: 2019/11/25 13:55:51 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/11/25 13:55:54 by hulamy ### ########.fr */
|
/* Updated: 2019/12/12 21:50:32 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -14,6 +14,27 @@
|
|||||||
** locate character in string and return its position
|
** locate character in string and return its position
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** void *ft_memchr(const void *s, int c, size_t n);
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** const char *str;
|
||||||
|
**
|
||||||
|
** char *pouet = "z";
|
||||||
|
** char *lolzer = (char *)&pouet[2];
|
||||||
|
** lolzer = "aaaaaaaaaa";
|
||||||
|
** str = ft_memchr(pouet, 'a', 50);
|
||||||
|
** if (!str)
|
||||||
|
** printf("NULL");
|
||||||
|
** else
|
||||||
|
** printf("%s\n", str);
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void *ft_memchr(const void *s, int c, size_t n)
|
void *ft_memchr(const void *s, int c, size_t n)
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_split.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/12/12 22:41:54 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/12/13 01:35:15 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** return an array of string with each word found in str, with c as separator
|
** return an array of string with each word found in str, with c as separator
|
||||||
*/
|
*/
|
||||||
@@ -47,16 +59,16 @@
|
|||||||
** char c;
|
** char c;
|
||||||
**
|
**
|
||||||
** i = -1;
|
** i = -1;
|
||||||
** s = "svh ile ifh oiuo";
|
** s = NULL;
|
||||||
** c = ' ';
|
** c = ' ';
|
||||||
** str = ft_split(s, c);
|
** str = ft_split(s, c);
|
||||||
** if (str)
|
** //if (str)
|
||||||
** {
|
** //{
|
||||||
** printf("s : '%s'\n", s);
|
** printf("s : '%s'\n", s);
|
||||||
** printf("*str : '%p'\n", str[0]);
|
** printf("*str : '%p'\n", str[0]);
|
||||||
** while (str[++i])
|
** while (str[++i])
|
||||||
** printf("str[%i] : '%s'\n", i, str[i]);
|
** printf("str[%i] : '%s'\n", i, str[i]);
|
||||||
** }
|
** //}
|
||||||
** return (0);
|
** return (0);
|
||||||
** }
|
** }
|
||||||
*/
|
*/
|
||||||
@@ -88,15 +100,25 @@ void *ft_free(char **array, int w)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char **empty_s(char **empty)
|
||||||
|
{
|
||||||
|
if (!(empty = (char **)malloc(sizeof(char *) * 1)))
|
||||||
|
return (NULL);
|
||||||
|
empty[0] = NULL;
|
||||||
|
return (empty);
|
||||||
|
}
|
||||||
|
|
||||||
char **ft_split(char const *s, char c)
|
char **ft_split(char const *s, char c)
|
||||||
{
|
{
|
||||||
char **array;
|
char **array;
|
||||||
int w;
|
int w;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
w = 0;
|
if (!s)
|
||||||
if (!s || !(array = (char **)malloc(sizeof(char *) * 1000 * (count(s, c) + 1))))
|
return (empty_s(NULL));
|
||||||
|
if (!(array = (char **)malloc(sizeof(char *) * (count(s, c) + 1))))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
w = 0;
|
||||||
while (*s != '\0')
|
while (*s != '\0')
|
||||||
{
|
{
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|||||||
@@ -51,6 +51,17 @@ void print_ft_strtrim(char const *s, char const *set)
|
|||||||
printf("strtrim: [%s] [%s] -> '%s'\n", s, set, ft_strtrim(s, set));
|
printf("strtrim: [%s] [%s] -> '%s'\n", s, set, ft_strtrim(s, set));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_ft_putnbr_fd(int n, int fd)
|
||||||
|
{
|
||||||
|
write(1, "putnbr : [", 10);
|
||||||
|
ft_putnbr_fd(n, 1);
|
||||||
|
write(1, "] [", 3);
|
||||||
|
ft_putnbr_fd(fd, 1);
|
||||||
|
write(1, "] -> '", 6);
|
||||||
|
ft_putnbr_fd(n, fd);
|
||||||
|
write(1, "'\n", 2);
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
char touppercase(unsigned int, char);
|
char touppercase(unsigned int, char);
|
||||||
@@ -61,12 +72,15 @@ int main()
|
|||||||
print_ft_itoa(1);
|
print_ft_itoa(1);
|
||||||
print_ft_itoa(-1218927987);
|
print_ft_itoa(-1218927987);
|
||||||
print_ft_itoa(128979827);
|
print_ft_itoa(128979827);
|
||||||
|
print_ft_itoa(2147483647);
|
||||||
|
print_ft_itoa(-2147483648);
|
||||||
|
print_ft_itoa('t');
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
print_ft_split(" dfs zfe f ez f fez ", ' ');
|
print_ft_split(" dfs zfe f ez f fez ", ' ');
|
||||||
print_ft_split(NULL, ' ');
|
|
||||||
print_ft_split(NULL, 0);
|
print_ft_split(NULL, 0);
|
||||||
|
print_ft_split(NULL, ' ');
|
||||||
print_ft_split("", 0);
|
print_ft_split("", 0);
|
||||||
print_ft_split("vzevzev fze", 0);
|
print_ft_split("vzevzev fze", 0);
|
||||||
print_ft_split(" ", 0);
|
print_ft_split(" ", 0);
|
||||||
@@ -86,6 +100,7 @@ int main()
|
|||||||
print_ft_strjoin(NULL, "fsdf");
|
print_ft_strjoin(NULL, "fsdf");
|
||||||
print_ft_strjoin("", NULL);
|
print_ft_strjoin("", NULL);
|
||||||
print_ft_strjoin("sdffez", NULL);
|
print_ft_strjoin("sdffez", NULL);
|
||||||
|
print_ft_strjoin(" ", " ");
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
@@ -115,7 +130,8 @@ int main()
|
|||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
print_ft_strtrim(" strtrim ", "m ");
|
print_ft_strtrim(" stmr trim ", "m ");
|
||||||
|
print_ft_strtrim(" ", " ");
|
||||||
print_ft_strtrim("", "");
|
print_ft_strtrim("", "");
|
||||||
print_ft_strtrim(NULL, "");
|
print_ft_strtrim(NULL, "");
|
||||||
print_ft_strtrim("", NULL);
|
print_ft_strtrim("", NULL);
|
||||||
@@ -123,5 +139,19 @@ int main()
|
|||||||
print_ft_strtrim("efzfe fzef", "");
|
print_ft_strtrim("efzfe fzef", "");
|
||||||
print_ft_strtrim("efzfzelelijz", " ");
|
print_ft_strtrim("efzfzelelijz", " ");
|
||||||
print_ft_strtrim(" e f zfzelelijz ", " ");
|
print_ft_strtrim(" e f zfzelelijz ", " ");
|
||||||
|
print_ft_strtrim("cccccccccccccccccccc", "c");
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
print_ft_putnbr_fd(52, 1);
|
||||||
|
print_ft_putnbr_fd(2147483647, 1);
|
||||||
|
print_ft_putnbr_fd(-2147483648, 1);
|
||||||
|
print_ft_putnbr_fd(0, 1);
|
||||||
|
print_ft_putnbr_fd(-1, 1);
|
||||||
|
print_ft_putnbr_fd(239847, 1);
|
||||||
|
print_ft_putnbr_fd(34625725, 1);
|
||||||
|
print_ft_putnbr_fd(-4564562, 1);
|
||||||
|
print_ft_putnbr_fd(456, 1);
|
||||||
|
print_ft_putnbr_fd(-624724536, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user