commit
This commit is contained in:
5
C_01/git_old/.gitignore
vendored
5
C_01/git_old/.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
**/main.c
|
|
||||||
**/main.sh
|
|
||||||
**/a.out
|
|
||||||
**/a.sh
|
|
||||||
**/Makefile
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_ft.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 09:25:38 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/09 09:25:41 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_ft(int *nbr)
|
|
||||||
{
|
|
||||||
*nbr = 42;
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_ultimate_ft.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 10:33:47 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/09 10:33:48 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_ultimate_ft(int *********nbr)
|
|
||||||
{
|
|
||||||
*********nbr = 42;
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_swap.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 10:49:30 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/09 10:49:42 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_swap(int *a, int *b)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = *a;
|
|
||||||
*a = *b;
|
|
||||||
*b = n;
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_div_mod.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 10:57:04 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/09 10:58:25 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_div_mod(int a, int b, int *div, int *mod)
|
|
||||||
{
|
|
||||||
*div = a / b;
|
|
||||||
*mod = a % b;
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_ultimate_div_mod.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 11:11:27 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/09 11:11:29 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_ultimate_div_mod(int *a, int *b)
|
|
||||||
{
|
|
||||||
int div;
|
|
||||||
int mod;
|
|
||||||
|
|
||||||
div = *a / *b;
|
|
||||||
mod = *a % *b;
|
|
||||||
*a = div;
|
|
||||||
*b = mod;
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 11:19:27 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/09 17:03:09 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void ft_putstr(char *str)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size] != '\0')
|
|
||||||
{
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
write(1, str, size);
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlen.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 11:23:08 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/09 17:03:24 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_strlen(char *str)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size] != '\0')
|
|
||||||
{
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_rev_int_tab.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 13:52:33 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/09 17:02:29 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_rev_int_tab(int *tab, int size)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < (size / 2))
|
|
||||||
{
|
|
||||||
j = size - 1 - i;
|
|
||||||
n = tab[i];
|
|
||||||
tab[i] = tab[j];
|
|
||||||
tab[j] = n;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_sort_int_tab.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 14:23:41 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/09 14:49:11 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_sort_int_tab(int *tab, int size)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int pass;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
pass = size - 1;
|
|
||||||
while (pass--)
|
|
||||||
{
|
|
||||||
i = 0;
|
|
||||||
while (i < size - 1)
|
|
||||||
{
|
|
||||||
if (tab[i] > tab[i + 1])
|
|
||||||
{
|
|
||||||
n = tab[i];
|
|
||||||
tab[i] = tab[i + 1];
|
|
||||||
tab[i + 1] = n;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
7
C_02/git_old/.gitignore
vendored
7
C_02/git_old/.gitignore
vendored
@@ -1,7 +0,0 @@
|
|||||||
**/main.c
|
|
||||||
**/main.sh
|
|
||||||
**/a.out
|
|
||||||
**/a.sh
|
|
||||||
**/Makefile
|
|
||||||
**/*.swp
|
|
||||||
**/*~
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 13:27:29 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/11 14:49:52 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
char *ft_strcpy(char *dest, char *src)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int src_size;
|
|
||||||
int dest_size;
|
|
||||||
|
|
||||||
src_size = 0;
|
|
||||||
while (src[src_size++] != '\0')
|
|
||||||
continue ;
|
|
||||||
dest_size = 0;
|
|
||||||
while (dest[dest_size++] != '\0')
|
|
||||||
continue ;
|
|
||||||
i = 0;
|
|
||||||
while (i < src_size)
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (i < dest_size)
|
|
||||||
{
|
|
||||||
dest[i] = '\0';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strncpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 18:19:08 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/11 18:05:56 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
char *ft_strncpy(char *dest, char *src, unsigned int n)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
unsigned int dest_size;
|
|
||||||
|
|
||||||
dest_size = 0;
|
|
||||||
while (dest[dest_size++] != '\0')
|
|
||||||
continue ;
|
|
||||||
i = 0;
|
|
||||||
while (n > 0 && i < n)
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (i < dest_size)
|
|
||||||
{
|
|
||||||
printf("Hello\n");
|
|
||||||
dest[i] = '\0';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_str_is_alpha.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/09 17:43:26 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/10 09:58:08 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_str_is_alpha(char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int r;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size] != '\0')
|
|
||||||
{
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
r = 1;
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
r &= (str[i] >= 'a' && str[i] <= 'z') \
|
|
||||||
|| (str[i] >= 'A' && str[i] <= 'Z');
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (r);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_str_is_numeric.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/10 10:14:17 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/10 10:15:38 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_str_is_numeric(char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int r;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size] != '\0')
|
|
||||||
{
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
r = 1;
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
r &= (str[i] >= '0' && str[i] <= '9');
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (r);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_str_is_lowercase.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/10 10:45:53 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/10 10:45:56 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_str_is_lowercase(char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int r;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size] != '\0')
|
|
||||||
{
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
r = 1;
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
r &= (str[i] >= 'a' && str[i] <= 'z');
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (r);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_str_is_uppercase.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/10 10:47:51 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/10 10:48:16 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_str_is_uppercase(char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int r;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size] != '\0')
|
|
||||||
{
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
r = 1;
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
r &= (str[i] >= 'A' && str[i] <= 'Z');
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (r);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_str_is_printable.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/10 11:05:18 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/10 11:10:03 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_str_is_printable(char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int r;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size] != '\0')
|
|
||||||
{
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
r = 1;
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
r &= (str[i] >= ' ' && str[i] <= '~');
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (r);
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strupcase.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/10 11:15:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/10 11:25:39 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
char *ft_strupcase(char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size++] != '\0')
|
|
||||||
continue ;
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
if (str[i] >= 'a' && str[i] <= 'z')
|
|
||||||
str[i] = str[i] - 32;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlowcase.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/10 11:34:35 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/10 11:40:03 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
char *ft_strlowcase(char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size++] != '\0')
|
|
||||||
continue ;
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
if (str[i] >= 'A' && str[i] <= 'Z')
|
|
||||||
str[i] += 32;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcapitalize.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/10 11:43:39 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/11 09:11:42 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
char *ft_strcapitalize(char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int size;
|
|
||||||
char prev_c;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size++] != '\0')
|
|
||||||
continue ;
|
|
||||||
prev_c = ' ';
|
|
||||||
i = 0;
|
|
||||||
while (i < size - 1)
|
|
||||||
{
|
|
||||||
if (\
|
|
||||||
(str[i] >= 'a' && str[i] <= 'z') && \
|
|
||||||
(\
|
|
||||||
(prev_c >= ' ' && prev_c <= '/') || \
|
|
||||||
(prev_c >= ':' && prev_c <= '@') || \
|
|
||||||
(prev_c >= '[' && prev_c <= '`') || \
|
|
||||||
(prev_c >= '{' && prev_c <= '~') \
|
|
||||||
) \
|
|
||||||
)
|
|
||||||
str[i] -= 32;
|
|
||||||
prev_c = str[i++];
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/11 10:20:13 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/11 15:36:08 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
unsigned int ft_strlcpy(char *dest, char *src, unsigned int size)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
unsigned int src_size;
|
|
||||||
unsigned int dest_size;
|
|
||||||
|
|
||||||
src_size = 0;
|
|
||||||
while (src[src_size++] != '\0')
|
|
||||||
continue ;
|
|
||||||
dest_size = 0;
|
|
||||||
while (dest[dest_size++] != '\0')
|
|
||||||
continue ;
|
|
||||||
i = 0;
|
|
||||||
while (size > 0 && i < size - 1)
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (i < dest_size)
|
|
||||||
{
|
|
||||||
dest[i] = '\0';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (--src_size);
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr_non_printable.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/11 11:29:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/11 16:56:40 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
// for i in {0..255}; do printf "%02x" $i; done
|
|
||||||
void ft_putstr_non_printable(char *str)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
const char *hex = "000102030405060708090a\
|
|
||||||
0b0c0d0e0f101112131415\
|
|
||||||
161718191a1b1c1d1e1f20\
|
|
||||||
2122232425262728292a2b\
|
|
||||||
2c2d2e2f30313233343536\
|
|
||||||
3738393a3b3c3d3e3f4041\
|
|
||||||
42434445464748494a4b4c\
|
|
||||||
4d4e4f5051525354555657\
|
|
||||||
58595a5b5c5d5e5f606162\
|
|
||||||
636465666768696a6b6c6d\
|
|
||||||
6e6f707172737475767778\
|
|
||||||
797a7b7c7d7e7f80818283\
|
|
||||||
8485868788898a8b8c8d8e\
|
|
||||||
8f90919293949596979899\
|
|
||||||
9a9b9c9d9e9fa0a1a2a3a4\
|
|
||||||
a5a6a7a8a9aaabacadaeaf\
|
|
||||||
b0b1b2b3b4b5b6b7b8b9ba\
|
|
||||||
bbbcbdbebfc0c1c2c3c4c5\
|
|
||||||
c6c7c8c9cacbcccdcecfd0\
|
|
||||||
d1d2d3d4d5d6d7d8d9dadb\
|
|
||||||
dcdddedfe0e1e2e3e4e5e6\
|
|
||||||
e7e8e9eaebecedeeeff0f1\
|
|
||||||
f2f3f4f5f6f7f8f9fafbfc\
|
|
||||||
fdfeff";
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (str[size++] != '\0')
|
|
||||||
continue ;
|
|
||||||
while (--size)
|
|
||||||
{
|
|
||||||
if (*str >= ' ' && *str <= '~')
|
|
||||||
write(1, str, 1);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
write(1, "\\", 1);
|
|
||||||
write(1, hex + *str * 2, 2);
|
|
||||||
}
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlen.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 09:03:26 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/13 09:09:57 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_strlen(char *str)
|
|
||||||
{
|
|
||||||
char *p_str;
|
|
||||||
|
|
||||||
p_str = str;
|
|
||||||
while (*p_str != '\0')
|
|
||||||
p_str++;
|
|
||||||
return (p_str - str);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 09:02:59 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/13 09:03:17 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int ft_strlen(char *str);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
char str[32];
|
|
||||||
int result;
|
|
||||||
|
|
||||||
printf("Input String [max 31]: ");
|
|
||||||
scanf("%s", str);
|
|
||||||
result = ft_strlen(str);
|
|
||||||
printf("str=%s result=%d (ft_strlen)\n", str, result);
|
|
||||||
result = strlen(str);
|
|
||||||
printf("str=%s result=%d (strlen)\n", str, result);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 09:16:54 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/13 09:21:15 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void ft_putstr(char *str)
|
|
||||||
{
|
|
||||||
char *p_str;
|
|
||||||
|
|
||||||
p_str = str;
|
|
||||||
while (*p_str != '\0')
|
|
||||||
write(1, p_str++, 1);
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 09:13:32 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/13 09:20:53 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
void ft_putstr(char *str);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
char str[32];
|
|
||||||
|
|
||||||
printf("Input String [max 31]: ");
|
|
||||||
scanf("%s", str);
|
|
||||||
ft_putstr(str);
|
|
||||||
write(1, "\n", 1);
|
|
||||||
printf("str=%s (ft_putstr)\n", str);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putnbr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 09:24:02 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/13 14:47:24 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void ft_putnbr(int nb)
|
|
||||||
{
|
|
||||||
char c;
|
|
||||||
|
|
||||||
if (nb == -2147483648)
|
|
||||||
write(1, "-2147483648", 11);
|
|
||||||
else if (nb >= 10)
|
|
||||||
{
|
|
||||||
ft_putnbr(nb / 10);
|
|
||||||
ft_putnbr(nb % 10);
|
|
||||||
}
|
|
||||||
else if (nb < 0)
|
|
||||||
{
|
|
||||||
write(1, "-", 1);
|
|
||||||
nb *= -1;
|
|
||||||
ft_putnbr(nb / 10);
|
|
||||||
ft_putnbr(nb % 10);
|
|
||||||
}
|
|
||||||
else if (nb >= 0)
|
|
||||||
{
|
|
||||||
c = nb + '0';
|
|
||||||
write(1, &c, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 09:22:26 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/13 11:18:57 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
void ft_putnbr(int nb);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int nb;
|
|
||||||
|
|
||||||
printf("Input Number: ");
|
|
||||||
scanf("%d", &nb);
|
|
||||||
ft_putnbr(nb);
|
|
||||||
write(1, "\n", 1);
|
|
||||||
printf("nb=%d (ft_putnbr)\n", nb);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_atoi.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 12:46:22 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/13 14:58:30 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_atoi(char *str)
|
|
||||||
{
|
|
||||||
int nb;
|
|
||||||
int s;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
nb = 0;
|
|
||||||
s = 0;
|
|
||||||
i = 0;
|
|
||||||
while (str[i] != '\0')
|
|
||||||
{
|
|
||||||
if (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r'))
|
|
||||||
s += 0;
|
|
||||||
else if (str[i] == '+')
|
|
||||||
s++;
|
|
||||||
else if (str[i] == '-')
|
|
||||||
s--;
|
|
||||||
else if (str[i] >= '0' && str[i] <= '9')
|
|
||||||
nb = nb * 10 + str[i] - '0';
|
|
||||||
else
|
|
||||||
break ;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (s < 0)
|
|
||||||
nb *= -1;
|
|
||||||
return (nb);
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 12:46:41 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/13 13:58:09 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int ft_atoi(char *str);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
char str[32];
|
|
||||||
int result;
|
|
||||||
|
|
||||||
printf("Input String [31]: ");
|
|
||||||
scanf("%s", str);
|
|
||||||
result = ft_atoi(str);
|
|
||||||
printf("str=%s result=%d (ft_atoi)\n", str, result);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strdup.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 09:03:26 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 11:29:47 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
char *ft_strdup(char *src)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
char *_str;
|
|
||||||
char *_src;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (src[size] != '\0')
|
|
||||||
size++;
|
|
||||||
str = (char *) malloc((size + 1) * sizeof(char));
|
|
||||||
if (str == NULL)
|
|
||||||
return (NULL);
|
|
||||||
_str = str;
|
|
||||||
_src = src;
|
|
||||||
while (*src != '\0')
|
|
||||||
*str++ = *src++;
|
|
||||||
*str = '\0';
|
|
||||||
str = _str;
|
|
||||||
src = _src;
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 09:02:59 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/18 18:07:36 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
char *ft_strdup(char *src);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
char *src;
|
|
||||||
char *result;
|
|
||||||
|
|
||||||
src = (char *) malloc(32 * sizeof(char));
|
|
||||||
printf("Input String [max 31]: ");
|
|
||||||
scanf("%s", src);
|
|
||||||
result = ft_strdup(src);
|
|
||||||
printf("src=%s result=%s (ft_strdup)\n", src, result);
|
|
||||||
result = strdup(src);
|
|
||||||
printf("src=%s result=%s (strdup)\n", src, result);
|
|
||||||
free(src);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_range.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/18 18:13:35 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 10:49:02 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
static int ft_abs(int n)
|
|
||||||
{
|
|
||||||
if (n < 0)
|
|
||||||
n = -n;
|
|
||||||
return (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
int *ft_range(int min, int max)
|
|
||||||
{
|
|
||||||
int *range;
|
|
||||||
int size;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
range = NULL;
|
|
||||||
if (min >= max)
|
|
||||||
return (range);
|
|
||||||
else
|
|
||||||
size = ft_abs(max - min);
|
|
||||||
range = (int *) malloc(size * sizeof(int));
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
range[i] = min + i;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (range);
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/18 18:11:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/19 16:11:21 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int *ft_range(int min, int max);
|
|
||||||
|
|
||||||
static int ft_abs(int n)
|
|
||||||
{
|
|
||||||
if (n < 0)
|
|
||||||
n = -n;
|
|
||||||
return (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int min;
|
|
||||||
int max;
|
|
||||||
int size;
|
|
||||||
int *result;
|
|
||||||
|
|
||||||
min = 0;
|
|
||||||
max = 0;
|
|
||||||
printf("Input Min: ");
|
|
||||||
scanf("%d", &min);
|
|
||||||
printf("Input Max: ");
|
|
||||||
scanf("%d", &max);
|
|
||||||
result = ft_range(min, max);
|
|
||||||
printf("min=%d max=%d (ft_range)\nresult:\n", min, max);
|
|
||||||
size = ft_abs(max - min);
|
|
||||||
printf("size=%d\n", size);
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
printf("result[%d] = %d\n", i, result[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_ultimate_range.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/18 18:13:35 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 10:49:32 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
static int ft_abs(int n)
|
|
||||||
{
|
|
||||||
if (n < 0)
|
|
||||||
n = -n;
|
|
||||||
return (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
int *ft_range(int min, int max)
|
|
||||||
{
|
|
||||||
int *range;
|
|
||||||
int size;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
range = NULL;
|
|
||||||
if (min >= max)
|
|
||||||
return (range);
|
|
||||||
else
|
|
||||||
size = ft_abs(max - min);
|
|
||||||
range = (int *) malloc(size * sizeof(int));
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
range[i] = min + i;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (range);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_ultimate_range(int **range, int min, int max)
|
|
||||||
{
|
|
||||||
int *r;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
(void) range;
|
|
||||||
r = NULL;
|
|
||||||
size = 0;
|
|
||||||
if (min >= max)
|
|
||||||
{
|
|
||||||
*range = r;
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
size = ft_abs(max - min);
|
|
||||||
r = ft_range(min, max);
|
|
||||||
*range = r;
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/18 18:11:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/18 18:31:33 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int ft_ultimate_range(int **range, int min, int max);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int min;
|
|
||||||
int max;
|
|
||||||
int size;
|
|
||||||
int *range;
|
|
||||||
|
|
||||||
min = 0;
|
|
||||||
max = 0;
|
|
||||||
size = 0;
|
|
||||||
printf("Input Min: ");
|
|
||||||
scanf("%d", &min);
|
|
||||||
printf("Input Max: ");
|
|
||||||
scanf("%d", &max);
|
|
||||||
size = ft_ultimate_range(&range, min, max);
|
|
||||||
printf("size=%d min=%d max=%d (ft_ultimate_range)\nrange:\n", size, min, max);
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
printf("range[%d] = %d\n", i, range[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strjoin.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/19 11:25:51 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 11:41:49 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
static int ft_strlen(char *str)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
|
|
||||||
len = 0;
|
|
||||||
while (str[len] != '\0')
|
|
||||||
len++;
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strcat(char *dest, char *src)
|
|
||||||
{
|
|
||||||
char *s1;
|
|
||||||
char *s2;
|
|
||||||
|
|
||||||
s1 = dest;
|
|
||||||
s2 = src;
|
|
||||||
while (*s1 != '\0')
|
|
||||||
s1++;
|
|
||||||
while (*s2 != '\0')
|
|
||||||
*s1++ = *s2++;
|
|
||||||
*s1 = '\0';
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_strslen(int size, char **strs, char *sep)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
len = 1;
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
len += ft_strlen(strs[i]);
|
|
||||||
if (i < size - 1)
|
|
||||||
len += ft_strlen(sep);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strjoin(int size, char **strs, char *sep)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
int len;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (size == 0)
|
|
||||||
{
|
|
||||||
str = (char *) malloc(sizeof(char));
|
|
||||||
*str = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
len = ft_strslen(size, strs, sep);
|
|
||||||
str = (char *) malloc(len * sizeof(char));
|
|
||||||
if (str == NULL)
|
|
||||||
return (NULL);
|
|
||||||
*str = '\0';
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
ft_strcat(str, strs[i]);
|
|
||||||
if (i < size - 1)
|
|
||||||
ft_strcat(str, sep);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 09:34:53 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 09:36:09 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
char *ft_strjoin(int size, char **strs, char *sep);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *sep;
|
|
||||||
char **strs;
|
|
||||||
char *result;
|
|
||||||
|
|
||||||
sep = "";
|
|
||||||
strs = malloc(3 * sizeof(*strs));
|
|
||||||
sep = (char *) malloc(32 * sizeof(char));
|
|
||||||
i = 0;
|
|
||||||
while (i < 3)
|
|
||||||
{
|
|
||||||
strs[i] = (char *) malloc(32 * sizeof(char));
|
|
||||||
printf("Input String #%d [Max 31]: ", i + 1);
|
|
||||||
scanf("%s", strs[i++]);
|
|
||||||
}
|
|
||||||
printf("Input Separator: ");
|
|
||||||
scanf("%s", sep);
|
|
||||||
result = ft_strjoin(i, strs, sep);
|
|
||||||
printf("size=%d sep=%s result=%s (ft_strjoin)\n", i, sep, result);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
rm -f a.out
|
|
||||||
#norminette -R CheckForbiddenSourceHeader
|
|
||||||
norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out ft_*.c main.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strdup.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 09:03:26 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 11:29:47 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
char *ft_strdup(char *src)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
char *_str;
|
|
||||||
char *_src;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
while (src[size] != '\0')
|
|
||||||
size++;
|
|
||||||
str = (char *) malloc((size + 1) * sizeof(char));
|
|
||||||
if (str == NULL)
|
|
||||||
return (NULL);
|
|
||||||
_str = str;
|
|
||||||
_src = src;
|
|
||||||
while (*src != '\0')
|
|
||||||
*str++ = *src++;
|
|
||||||
*str = '\0';
|
|
||||||
str = _str;
|
|
||||||
src = _src;
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/13 09:02:59 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/18 18:07:36 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
char *ft_strdup(char *src);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
char *src;
|
|
||||||
char *result;
|
|
||||||
|
|
||||||
src = (char *) malloc(32 * sizeof(char));
|
|
||||||
printf("Input String [max 31]: ");
|
|
||||||
scanf("%s", src);
|
|
||||||
result = ft_strdup(src);
|
|
||||||
printf("src=%s result=%s (ft_strdup)\n", src, result);
|
|
||||||
result = strdup(src);
|
|
||||||
printf("src=%s result=%s (strdup)\n", src, result);
|
|
||||||
free(src);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_range.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/18 18:13:35 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 10:49:02 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
static int ft_abs(int n)
|
|
||||||
{
|
|
||||||
if (n < 0)
|
|
||||||
n = -n;
|
|
||||||
return (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
int *ft_range(int min, int max)
|
|
||||||
{
|
|
||||||
int *range;
|
|
||||||
int size;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
range = NULL;
|
|
||||||
if (min >= max)
|
|
||||||
return (range);
|
|
||||||
else
|
|
||||||
size = ft_abs(max - min);
|
|
||||||
range = (int *) malloc(size * sizeof(int));
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
range[i] = min + i;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (range);
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/18 18:11:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/19 16:11:21 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int *ft_range(int min, int max);
|
|
||||||
|
|
||||||
static int ft_abs(int n)
|
|
||||||
{
|
|
||||||
if (n < 0)
|
|
||||||
n = -n;
|
|
||||||
return (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int min;
|
|
||||||
int max;
|
|
||||||
int size;
|
|
||||||
int *result;
|
|
||||||
|
|
||||||
min = 0;
|
|
||||||
max = 0;
|
|
||||||
printf("Input Min: ");
|
|
||||||
scanf("%d", &min);
|
|
||||||
printf("Input Max: ");
|
|
||||||
scanf("%d", &max);
|
|
||||||
result = ft_range(min, max);
|
|
||||||
printf("min=%d max=%d (ft_range)\nresult:\n", min, max);
|
|
||||||
size = ft_abs(max - min);
|
|
||||||
printf("size=%d\n", size);
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
printf("result[%d] = %d\n", i, result[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_ultimate_range.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/18 18:13:35 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 10:49:32 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
static int ft_abs(int n)
|
|
||||||
{
|
|
||||||
if (n < 0)
|
|
||||||
n = -n;
|
|
||||||
return (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
int *ft_range(int min, int max)
|
|
||||||
{
|
|
||||||
int *range;
|
|
||||||
int size;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
range = NULL;
|
|
||||||
if (min >= max)
|
|
||||||
return (range);
|
|
||||||
else
|
|
||||||
size = ft_abs(max - min);
|
|
||||||
range = (int *) malloc(size * sizeof(int));
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
range[i] = min + i;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (range);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_ultimate_range(int **range, int min, int max)
|
|
||||||
{
|
|
||||||
int *r;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
(void) range;
|
|
||||||
r = NULL;
|
|
||||||
size = 0;
|
|
||||||
if (min >= max)
|
|
||||||
{
|
|
||||||
*range = r;
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
size = ft_abs(max - min);
|
|
||||||
r = ft_range(min, max);
|
|
||||||
*range = r;
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/18 18:11:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/18 18:31:33 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int ft_ultimate_range(int **range, int min, int max);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int min;
|
|
||||||
int max;
|
|
||||||
int size;
|
|
||||||
int *range;
|
|
||||||
|
|
||||||
min = 0;
|
|
||||||
max = 0;
|
|
||||||
size = 0;
|
|
||||||
printf("Input Min: ");
|
|
||||||
scanf("%d", &min);
|
|
||||||
printf("Input Max: ");
|
|
||||||
scanf("%d", &max);
|
|
||||||
size = ft_ultimate_range(&range, min, max);
|
|
||||||
printf("size=%d min=%d max=%d (ft_ultimate_range)\nrange:\n", size, min, max);
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
printf("range[%d] = %d\n", i, range[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strjoin.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/19 11:25:51 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 11:41:49 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
static int ft_strlen(char *str)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
|
|
||||||
len = 0;
|
|
||||||
while (str[len] != '\0')
|
|
||||||
len++;
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strcat(char *dest, char *src)
|
|
||||||
{
|
|
||||||
char *s1;
|
|
||||||
char *s2;
|
|
||||||
|
|
||||||
s1 = dest;
|
|
||||||
s2 = src;
|
|
||||||
while (*s1 != '\0')
|
|
||||||
s1++;
|
|
||||||
while (*s2 != '\0')
|
|
||||||
*s1++ = *s2++;
|
|
||||||
*s1 = '\0';
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_strslen(int size, char **strs, char *sep)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
len = 1;
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
len += ft_strlen(strs[i]);
|
|
||||||
if (i < size - 1)
|
|
||||||
len += ft_strlen(sep);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strjoin(int size, char **strs, char *sep)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
int len;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (size == 0)
|
|
||||||
{
|
|
||||||
str = (char *) malloc(sizeof(char));
|
|
||||||
*str = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
len = ft_strslen(size, strs, sep);
|
|
||||||
str = (char *) malloc(len * sizeof(char));
|
|
||||||
if (str == NULL)
|
|
||||||
return (NULL);
|
|
||||||
*str = '\0';
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
ft_strcat(str, strs[i]);
|
|
||||||
if (i < size - 1)
|
|
||||||
ft_strcat(str, sep);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 09:34:53 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 09:36:09 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
char *ft_strjoin(int size, char **strs, char *sep);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *sep;
|
|
||||||
char **strs;
|
|
||||||
char *result;
|
|
||||||
|
|
||||||
sep = "";
|
|
||||||
strs = malloc(3 * sizeof(*strs));
|
|
||||||
sep = (char *) malloc(32 * sizeof(char));
|
|
||||||
i = 0;
|
|
||||||
while (i < 3)
|
|
||||||
{
|
|
||||||
strs[i] = (char *) malloc(32 * sizeof(char));
|
|
||||||
printf("Input String #%d [Max 31]: ", i + 1);
|
|
||||||
scanf("%s", strs[i++]);
|
|
||||||
}
|
|
||||||
printf("Input Separator: ");
|
|
||||||
scanf("%s", sep);
|
|
||||||
result = ft_strjoin(i, strs, sep);
|
|
||||||
printf("size=%d sep=%s result=%s (ft_strjoin)\n", i, sep, result);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
rm -f a.out
|
|
||||||
#norminette -R CheckForbiddenSourceHeader
|
|
||||||
norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out ft_*.c main.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 12:05:50 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#ifndef FT_H
|
|
||||||
# define FT_H
|
|
||||||
|
|
||||||
void ft_putchar(char c);
|
|
||||||
void ft_swap(int *a, int *b);
|
|
||||||
void ft_putstr(char *str);
|
|
||||||
int ft_strlen(char *str);
|
|
||||||
int ft_strcmp(char *s1, char *s2);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 10:26:50 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 10:34:14 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft.h"
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
(void) argc;
|
|
||||||
(void) argv;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
rm -f a.out
|
|
||||||
find . -type f -name '*.h' -exec \
|
|
||||||
norminette -R CheckDefine {} \;
|
|
||||||
find . -type f -name '*.c' \! -name 'main.c' -exec \
|
|
||||||
norminette -R CheckForbiddenSourceHeader {} \;
|
|
||||||
echo
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
#cpp *.c | tail -n 30
|
|
||||||
echo
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out "$@"
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_boolean.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 15:41:04 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#ifndef FT_BOOLEAN_H
|
|
||||||
# define FT_BOOLEAN_H
|
|
||||||
|
|
||||||
# include <unistd.h>
|
|
||||||
|
|
||||||
typedef int t_bool;
|
|
||||||
|
|
||||||
# define TRUE 1
|
|
||||||
# define FALSE 0
|
|
||||||
# define EVEN(nbr) nbr % 2 == 0
|
|
||||||
# define EVEN_MSG "I have an even number of arguments.\n"
|
|
||||||
# define ODD_MSG "I have an odd number of arguments.\n"
|
|
||||||
# define SUCCESS 0
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 10:26:50 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 10:34:14 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_boolean.h"
|
|
||||||
|
|
||||||
void ft_putstr(char *str)
|
|
||||||
{
|
|
||||||
while (*str)
|
|
||||||
write(1, str++, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
t_bool ft_is_even(int nbr)
|
|
||||||
{
|
|
||||||
return ((EVEN(nbr)) ? TRUE : FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
(void) argv;
|
|
||||||
if (ft_is_even(argc - 1) == TRUE)
|
|
||||||
ft_putstr(EVEN_MSG);
|
|
||||||
else
|
|
||||||
ft_putstr(ODD_MSG);
|
|
||||||
return (SUCCESS);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
rm -f a.out
|
|
||||||
find . -type f -name '*.h' -exec \
|
|
||||||
norminette -R CheckDefine {} \;
|
|
||||||
find . -type f -name '*.c' \! -name 'main.c' -exec \
|
|
||||||
norminette -R CheckForbiddenSourceHeader {} \;
|
|
||||||
echo
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
#cpp *.c | tail -n 30
|
|
||||||
echo
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out "$@"
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_boolean.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 15:39:27 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef FT_ABS_H
|
|
||||||
# define FT_ABS_H
|
|
||||||
|
|
||||||
# define ABS(Value) ((Value < 0)? (-Value): (Value))
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 10:26:50 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 10:34:14 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_abs.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
static int ft_atoi(char *str)
|
|
||||||
{
|
|
||||||
int nb;
|
|
||||||
int s;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
nb = 0;
|
|
||||||
s = 1;
|
|
||||||
i = 0;
|
|
||||||
while (str[i] != '\0' && (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r')))
|
|
||||||
i++;
|
|
||||||
while (str[i] != '\0')
|
|
||||||
{
|
|
||||||
if (str[i] == '+')
|
|
||||||
s += 0;
|
|
||||||
else if (str[i] == '-')
|
|
||||||
s *= -1;
|
|
||||||
else if (str[i] >= '0' && str[i] <= '9')
|
|
||||||
nb = nb * 10 + str[i] - '0';
|
|
||||||
else
|
|
||||||
break ;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (nb * s);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
if (argc > 1)
|
|
||||||
{
|
|
||||||
n = ft_atoi(argv[1]);
|
|
||||||
printf("%d\n", ABS(n));
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
rm -f a.out
|
|
||||||
find . -type f -name '*.h' -exec \
|
|
||||||
norminette -R CheckDefine {} \;
|
|
||||||
find . -type f -name '*.c' \! -name 'main.c' -exec \
|
|
||||||
norminette -R CheckForbiddenSourceHeader {} \;
|
|
||||||
echo
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
#cpp *.c | tail -n 30
|
|
||||||
echo
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out "$@"
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_point.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 12:05:50 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef FT_POINT_H
|
|
||||||
# define FT_POINT_H
|
|
||||||
|
|
||||||
typedef struct s_point
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
} t_point;
|
|
||||||
void set_point(t_point *point);
|
|
||||||
#endif
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 10:26:50 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 10:34:14 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_point.h"
|
|
||||||
|
|
||||||
void set_point(t_point *point)
|
|
||||||
{
|
|
||||||
point->x = 42;
|
|
||||||
point->y = 21;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
t_point point;
|
|
||||||
|
|
||||||
set_point(&point);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
rm -f a.out
|
|
||||||
find . -type f -name '*.h' -exec \
|
|
||||||
norminette -R CheckDefine {} \;
|
|
||||||
find . -type f -name '*.c' \! -name 'main.c' -exec \
|
|
||||||
norminette -R CheckForbiddenSourceHeader {} \;
|
|
||||||
echo
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
#cpp *.c | tail -n 30
|
|
||||||
echo
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out "$@"
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/20 12:05:50 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#ifndef FT_H
|
|
||||||
# define FT_H
|
|
||||||
|
|
||||||
void ft_putchar(char c);
|
|
||||||
void ft_swap(int *a, int *b);
|
|
||||||
void ft_putstr(char *str);
|
|
||||||
int ft_strlen(char *str);
|
|
||||||
int ft_strcmp(char *s1, char *s2);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putchar.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:41:08 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:41:17 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void ft_putchar(char c)
|
|
||||||
{
|
|
||||||
write(1, &c, 1);
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:42:02 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:42:04 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void ft_putstr(char *str)
|
|
||||||
{
|
|
||||||
char *p_str;
|
|
||||||
|
|
||||||
p_str = str;
|
|
||||||
while (*p_str != '\0')
|
|
||||||
write(1, p_str++, 1);
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:43:35 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:43:44 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_strcmp(char *s1, char *s2)
|
|
||||||
{
|
|
||||||
char c1;
|
|
||||||
char c2;
|
|
||||||
|
|
||||||
c1 = '\0';
|
|
||||||
c2 = '\0';
|
|
||||||
while (c1 == c2)
|
|
||||||
{
|
|
||||||
c1 = *s1++;
|
|
||||||
c2 = *s2++;
|
|
||||||
if (c1 == '\0')
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
return (c1 - c2);
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlen.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:42:47 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:43:21 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_strlen(char *str)
|
|
||||||
{
|
|
||||||
char *p_str;
|
|
||||||
|
|
||||||
p_str = str;
|
|
||||||
while (*p_str != '\0')
|
|
||||||
p_str++;
|
|
||||||
return (p_str - str);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_swap.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:41:30 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:41:35 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_swap(int *a, int *b)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = *a;
|
|
||||||
*a = *b;
|
|
||||||
*b = n;
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
rm -f *.o libft.a
|
|
||||||
gcc -Wall -Wextra -Werror -c *.c
|
|
||||||
ar -cq libft.a *.o
|
|
||||||
#ar -t libft.a
|
|
||||||
#rm -f *.o
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:55:33 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 17:19:48 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
void ft_putchar(char c);
|
|
||||||
void ft_swap(int *a, int *b);
|
|
||||||
void ft_putstr(char *str);
|
|
||||||
int ft_strlen(char *str);
|
|
||||||
int ft_strcmp(char *s1, char *s2);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int a;
|
|
||||||
int b;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
printf("ft_putchar: (expected Z)\n");
|
|
||||||
ft_putchar('Z');
|
|
||||||
printf("\n\n");
|
|
||||||
a = 42;
|
|
||||||
b = 21;
|
|
||||||
printf("ft_swap: (expected a=21 b=42)\n");
|
|
||||||
ft_swap(&a, &b);
|
|
||||||
printf("a=%d b=%d\n\n", a, b);
|
|
||||||
printf("ft_putstr: (expected hello)\n");
|
|
||||||
ft_putstr("hello\n\n");
|
|
||||||
printf("ft_strlen: (expected 5)\n");
|
|
||||||
r = ft_strlen("hello");
|
|
||||||
printf("%d\n\n", r);
|
|
||||||
printf("ft_strcmp: (expected 0)\n");
|
|
||||||
r = ft_strcmp("abc","abc");
|
|
||||||
printf("%d\n\n", r);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
find . -type f -name '*.h' -exec \
|
|
||||||
norminette -R CheckDefine {} \;
|
|
||||||
find . -type f -name '*.c' \! -name 'main.c' -exec \
|
|
||||||
norminette -R CheckForbiddenSourceHeader {} \;
|
|
||||||
echo
|
|
||||||
sh libft_creator.sh
|
|
||||||
rm -f *.o
|
|
||||||
echo
|
|
||||||
echo $(basename $PWD):
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out -L. -lft main.c
|
|
||||||
./a.out "$@"
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
# **************************************************************************** #
|
|
||||||
# #
|
|
||||||
# ::: :::::::: #
|
|
||||||
# Makefile :+: :+: :+: #
|
|
||||||
# +:+ +:+ +:+ #
|
|
||||||
# By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ #
|
|
||||||
# +#+#+#+#+#+ +#+ #
|
|
||||||
# Created: 2021/08/22 17:28:57 by gbaconni #+# #+# #
|
|
||||||
# Updated: 2021/08/22 18:12:53 by gbaconni ### ########.fr #
|
|
||||||
# #
|
|
||||||
# **************************************************************************** #
|
|
||||||
|
|
||||||
#
|
|
||||||
# make fclean
|
|
||||||
# make
|
|
||||||
#
|
|
||||||
|
|
||||||
NAME = libft.a
|
|
||||||
|
|
||||||
SRCDIR = srcs
|
|
||||||
SRC = $(SRCDIR)/ft_putchar.c $(SRCDIR)/ft_swap.c $(SRCDIR)/ft_putstr.c $(SRCDIR)/ft_strlen.c $(SRCDIR)/ft_strcmp.c
|
|
||||||
OBJ = ${SRC:.c=.o}
|
|
||||||
|
|
||||||
HDRDIR = includes
|
|
||||||
HDR = $(HDRDIR)/ft.h
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
CFLAGS = -Wall -Wextra -Werror
|
|
||||||
AR = ar
|
|
||||||
ARFLAGS = -rcs
|
|
||||||
|
|
||||||
RM = rm
|
|
||||||
RMFLAGS = -f
|
|
||||||
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
.c.o:
|
|
||||||
$(CC) $(CFLAGS) -I $(HDRDIR) -c $< -o ${<:.c=.o}
|
|
||||||
|
|
||||||
$(NAME): $(OBJ)
|
|
||||||
$(AR) $(ARFLAGS) $@ $^
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) $(RMFLAGS) $(OBJ)
|
|
||||||
|
|
||||||
fclean: clean
|
|
||||||
$(RM) $(RMFLAGS) $(NAME)
|
|
||||||
|
|
||||||
re: fclean all
|
|
||||||
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 17:40:13 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#ifndef FT_H
|
|
||||||
# define FT_H
|
|
||||||
|
|
||||||
void ft_putchar(char c);
|
|
||||||
void ft_swap(int *a, int *b);
|
|
||||||
void ft_putstr(char *str);
|
|
||||||
int ft_strlen(char *str);
|
|
||||||
int ft_strcmp(char *s1, char *s2);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:55:33 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 17:19:48 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "ft.h"
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int a;
|
|
||||||
int b;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
printf("ft_putchar: (expected Z)\n");
|
|
||||||
ft_putchar('Z');
|
|
||||||
printf("\n\n");
|
|
||||||
a = 42;
|
|
||||||
b = 21;
|
|
||||||
printf("ft_swap: (expected a=21 b=42)\n");
|
|
||||||
ft_swap(&a, &b);
|
|
||||||
printf("a=%d b=%d\n\n", a, b);
|
|
||||||
printf("ft_putstr: (expected hello)\n");
|
|
||||||
ft_putstr("hello\n\n");
|
|
||||||
printf("ft_strlen: (expected 5)\n");
|
|
||||||
r = ft_strlen("hello");
|
|
||||||
printf("%d\n\n", r);
|
|
||||||
printf("ft_strcmp: (expected 0)\n");
|
|
||||||
r = ft_strcmp("abc","abc");
|
|
||||||
printf("%d\n\n", r);
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
find . -type f -name '*.h' -exec \
|
|
||||||
norminette -R CheckDefine {} \;
|
|
||||||
find . -type f -name '*.c' \! -name 'main.c' -exec \
|
|
||||||
norminette -R CheckForbiddenSourceHeader {} \;
|
|
||||||
echo
|
|
||||||
make fclean
|
|
||||||
make
|
|
||||||
echo
|
|
||||||
echo $(basename $PWD):
|
|
||||||
gcc -Wall -Wextra -Werror main.c -I includes -L . -lft -o a.out
|
|
||||||
./a.out "$@"
|
|
||||||
make fclean
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putchar.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:41:08 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:41:17 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void ft_putchar(char c)
|
|
||||||
{
|
|
||||||
write(1, &c, 1);
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:42:02 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:42:04 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void ft_putstr(char *str)
|
|
||||||
{
|
|
||||||
char *p_str;
|
|
||||||
|
|
||||||
p_str = str;
|
|
||||||
while (*p_str != '\0')
|
|
||||||
write(1, p_str++, 1);
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:43:35 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:43:44 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_strcmp(char *s1, char *s2)
|
|
||||||
{
|
|
||||||
char c1;
|
|
||||||
char c2;
|
|
||||||
|
|
||||||
c1 = '\0';
|
|
||||||
c2 = '\0';
|
|
||||||
while (c1 == c2)
|
|
||||||
{
|
|
||||||
c1 = *s1++;
|
|
||||||
c2 = *s2++;
|
|
||||||
if (c1 == '\0')
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
return (c1 - c2);
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlen.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:42:47 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:43:21 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_strlen(char *str)
|
|
||||||
{
|
|
||||||
char *p_str;
|
|
||||||
|
|
||||||
p_str = str;
|
|
||||||
while (*p_str != '\0')
|
|
||||||
p_str++;
|
|
||||||
return (p_str - str);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_swap.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:41:30 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:41:35 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_swap(int *a, int *b)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = *a;
|
|
||||||
*a = *b;
|
|
||||||
*b = n;
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_split.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 18:14:04 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/26 09:53:30 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int g_t = 0;
|
|
||||||
|
|
||||||
static char *ft_strncpy(char *dest, char *src, unsigned int n)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < n && src[i] != '\0')
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (i < n)
|
|
||||||
{
|
|
||||||
dest[i] = '\0';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
dest[i] = '\0';
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_is_charset(char c, char *charset)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (charset[i] != '\0')
|
|
||||||
{
|
|
||||||
if (c == charset[i])
|
|
||||||
return (1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_split_len(char *str, char *charset)
|
|
||||||
{
|
|
||||||
char *p_str;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 2;
|
|
||||||
if (str == NULL || charset == NULL)
|
|
||||||
return (size);
|
|
||||||
p_str = str;
|
|
||||||
while (*p_str != '\0')
|
|
||||||
{
|
|
||||||
if (ft_is_charset(*p_str++, charset) == 1)
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_copy(char *str, int size)
|
|
||||||
{
|
|
||||||
char *result;
|
|
||||||
|
|
||||||
result = (char *) malloc((size + 1) * sizeof(char));
|
|
||||||
if (!result)
|
|
||||||
return (NULL);
|
|
||||||
if (size > 0)
|
|
||||||
ft_strncpy(result, str, size);
|
|
||||||
else
|
|
||||||
result[0] = '\0';
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
char **ft_split(char *str, char *charset)
|
|
||||||
{
|
|
||||||
char **strs;
|
|
||||||
char *start;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
strs = malloc(ft_split_len(str, charset) * sizeof(strs));
|
|
||||||
if (strs == NULL || charset == NULL || str == NULL)
|
|
||||||
return (NULL);
|
|
||||||
start = str;
|
|
||||||
i = 0;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
if (ft_is_charset(*str, charset) == 1 || (*str == '\0' && g_t > 0))
|
|
||||||
{
|
|
||||||
if (str - start > 0)
|
|
||||||
strs[i++] = ft_copy(start, str - start);
|
|
||||||
start = str + 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
g_t++;
|
|
||||||
if (*str == '\0')
|
|
||||||
break ;
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
strs[i] = ft_copy(str, 0);
|
|
||||||
return (strs);
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/18 10:50:59 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/25 14:11:02 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
char **ft_split(char *str, char *charset);
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
char **strs;
|
|
||||||
char *str;
|
|
||||||
char *charset;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (argc < 2)
|
|
||||||
{
|
|
||||||
printf("%s <str> <charset>\n", argv[0]);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
str = argv[1];
|
|
||||||
charset = argv[2];
|
|
||||||
if (str[0] == '\0')
|
|
||||||
str = NULL;
|
|
||||||
strs = ft_split(str, charset);
|
|
||||||
printf("str=%s charset=%s (ft_split)\n", str, charset);
|
|
||||||
i = 0;
|
|
||||||
while (strs[i])
|
|
||||||
{
|
|
||||||
printf("strs[%d] = %s\n", i, strs[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
free(strs);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
rm -f a.out
|
|
||||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
|
||||||
norminette -R CheckForbiddenSourceHeader
|
|
||||||
#gcc -Wall -Wextra -Werror -fsanitize=address -g -o a.out *.c
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
|
||||||
echo $(basename $PWD):
|
|
||||||
./a.out "$@"
|
|
||||||
rm -f a.out
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putchar.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:41:08 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:41:17 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void ft_putchar(char c)
|
|
||||||
{
|
|
||||||
write(1, &c, 1);
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:42:02 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:42:04 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void ft_putstr(char *str)
|
|
||||||
{
|
|
||||||
char *p_str;
|
|
||||||
|
|
||||||
p_str = str;
|
|
||||||
while (*p_str != '\0')
|
|
||||||
write(1, p_str++, 1);
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:43:35 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:43:44 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_strcmp(char *s1, char *s2)
|
|
||||||
{
|
|
||||||
char c1;
|
|
||||||
char c2;
|
|
||||||
|
|
||||||
c1 = '\0';
|
|
||||||
c2 = '\0';
|
|
||||||
while (c1 == c2)
|
|
||||||
{
|
|
||||||
c1 = *s1++;
|
|
||||||
c2 = *s2++;
|
|
||||||
if (c1 == '\0')
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
return (c1 - c2);
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlen.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:42:47 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:43:21 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_strlen(char *str)
|
|
||||||
{
|
|
||||||
char *p_str;
|
|
||||||
|
|
||||||
p_str = str;
|
|
||||||
while (*p_str != '\0')
|
|
||||||
p_str++;
|
|
||||||
return (p_str - str);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_swap.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:41:30 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 14:41:35 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_swap(int *a, int *b)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = *a;
|
|
||||||
*a = *b;
|
|
||||||
*b = n;
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
rm -f *.o libft.a
|
|
||||||
gcc -Wall -Wextra -Werror -c *.c
|
|
||||||
ar -cq libft.a *.o
|
|
||||||
#ar -t libft.a
|
|
||||||
#rm -f *.o
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/08/22 14:55:33 by gbaconni #+# #+# */
|
|
||||||
/* Updated: 2021/08/22 17:19:48 by gbaconni ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
void ft_putchar(char c);
|
|
||||||
void ft_swap(int *a, int *b);
|
|
||||||
void ft_putstr(char *str);
|
|
||||||
int ft_strlen(char *str);
|
|
||||||
int ft_strcmp(char *s1, char *s2);
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int a;
|
|
||||||
int b;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
printf("ft_putchar: (expected Z)\n");
|
|
||||||
ft_putchar('Z');
|
|
||||||
printf("\n\n");
|
|
||||||
a = 42;
|
|
||||||
b = 21;
|
|
||||||
printf("ft_swap: (expected a=21 b=42)\n");
|
|
||||||
ft_swap(&a, &b);
|
|
||||||
printf("a=%d b=%d\n\n", a, b);
|
|
||||||
printf("ft_putstr: (expected hello)\n");
|
|
||||||
ft_putstr("hello\n\n");
|
|
||||||
printf("ft_strlen: (expected 5)\n");
|
|
||||||
r = ft_strlen("hello");
|
|
||||||
printf("%d\n\n", r);
|
|
||||||
printf("ft_strcmp: (expected 0)\n");
|
|
||||||
r = ft_strcmp("abc","abc");
|
|
||||||
printf("%d\n\n", r);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
find . -type f -name '*.h' -exec \
|
|
||||||
norminette -R CheckDefine {} \;
|
|
||||||
find . -type f -name '*.c' \! -name 'main.c' -exec \
|
|
||||||
norminette -R CheckForbiddenSourceHeader {} \;
|
|
||||||
echo
|
|
||||||
sh libft_creator.sh
|
|
||||||
rm -f *.o
|
|
||||||
echo
|
|
||||||
echo $(basename $PWD):
|
|
||||||
gcc -Wall -Wextra -Werror -o a.out -L. -lft main.c
|
|
||||||
./a.out "$@"
|
|
||||||
rm -f a.out
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user