Add C-Structures Exos

This commit is contained in:
lclerel- lclerel-
2026-03-26 01:43:52 +01:00
parent 19739f2619
commit 25e5442632
5 changed files with 344 additions and 5 deletions
+3 -3
View File
@@ -6,7 +6,7 @@
/* By: lclerel- <lclerel-@student.42.fr> +#+ +:+ +#+ */ /* By: lclerel- <lclerel-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/24 13:44:05 by lclerel- #+# #+# */ /* Created: 2026/03/24 13:44:05 by lclerel- #+# #+# */
/* Updated: 2026/03/25 16:39:44 by lclerel- ### ########.fr */ /* Updated: 2026/03/25 22:46:26 by lclerel- ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -22,7 +22,7 @@ int ft_strcmp(char *s1, char *s2)
return ((unsigned char)s1[i] - (unsigned char)s2[i]); return ((unsigned char)s1[i] - (unsigned char)s2[i]);
} }
void ft_putchar(char chara) /*void ft_putchar(char chara)
{ {
write(1, &chara, 1); write(1, &chara, 1);
} }
@@ -38,7 +38,7 @@ void ft_putstr(char *str)
i++; i++;
} }
} }
/*
int main(void) int main(void)
{ {
char *s1 = "Lumi"; char *s1 = "Lumi";
+2 -1
View File
@@ -6,10 +6,11 @@
/* By: lclerel- <lclerel-@student.42.fr> +#+ +:+ +#+ */ /* By: lclerel- <lclerel-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/24 13:44:05 by lclerel- #+# #+# */ /* Created: 2026/03/24 13:44:05 by lclerel- #+# #+# */
/* Updated: 2026/03/25 16:39:14 by lclerel- ### ########.fr */ /* Updated: 2026/03/25 22:46:55 by lclerel- ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <unistd.h>
int ft_strncmp(char *s1, char *s2, unsigned int n) int ft_strncmp(char *s1, char *s2, unsigned int n)
{ {
@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_point.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/25 22:49:49 by lclerel- #+# #+# */
/* Updated: 2026/03/25 22:53:42 by lclerel- ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_POINT_H
# define FT_POINT_H
typedef struct s_point
{
int x;
int y;
} t_point;
#endif
@@ -0,0 +1,179 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strs_to_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lclerel- <lclerel-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/25 22:54:18 by lclerel- #+# #+# */
/* Updated: 2026/03/26 01:19:03 by lclerel- ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stdlib.h>
#include "ft_stock_str.h"
char *ft_strdup(char *src);
int ft_strlen(char *str);
struct s_stock_str *ft_strs_to_tab(int ac, char **av)
{
t_stock_str *tab;
int i;
i = 0;
tab = malloc((ac + 1) * sizeof(t_stock_str));
if (!tab)
return (NULL);
while (i < ac)
{
tab[i].size = ft_strlen(av[i]);
tab[i].str = av[i];
tab[i].copy = ft_strdup(av[i]);
i++;
}
tab[i].str = av[i];
return (tab);
}
char *ft_strdup(char *src)
{
int i;
int len;
char *dst;
i = 0;
len = 0;
if (src == NULL)
return (NULL);
while (src[len])
len++;
dst = malloc(sizeof(char) * (len + 1));
if (dst == NULL)
{
return (NULL);
}
while (i < len)
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (dst);
}
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
i++;
}
return (i);
}
/*
void ft_putstr(char *str)
{
int i;
if (!str)
return ;
i = 0;
while (str[i])
{
write(1, &str[i], 1);
i++;
}
}
void ft_putnbr(int nb)
{
char value;
if (nb == -2147483648)
{
write(1, "-2147483648", 11);
return ;
}
if (nb < 0)
{
write(1, "-", 1);
nb = -nb;
}
if (nb > 9)
{
ft_putnbr(nb / 10);
}
value = nb % 10 + '0';
write(1, &value, 1);
}
void ft_stylebox(int n)
{
while (n > 0)
{
write(1, " ", 1);
n--;
}
}
int ft_nbrlen(int nb)
{
int len;
len = 1;
while (nb > 9)
{
nb /= 10;
len++;
}
return (len);
}
int main(int argc, char **argv)
{
t_stock_str *tab;
int i;
int spaces;
tab = ft_strs_to_tab(argc, argv);
if (!tab)
return (1);
i = 0;
while (tab[i].str != 0)
{
// Oui, cela ne sers a rien. A RIEN.
// mais c pour faire waw. et si sa te plait pas, bah...
// DARK MOULINETTE VA TE FAIRE DU SALE MON GARS !
// - Lumi, 26 Mars 2026, 0h24. Entrain de sombrer dans la folie.
ft_putstr("/==========================\\\n");
ft_putstr("| Taille : |\n");
ft_putstr("| > ");
ft_putnbr(tab[i].size);
spaces = 26 - 4 - ft_nbrlen(tab[i].size);
ft_stylebox(spaces);
ft_putstr("|\n");
ft_putstr("| String : |\n");
ft_putstr("| > ");
ft_putstr(tab[i].str);
spaces = 26 - 4 - ft_strlen(tab[i].str);
ft_stylebox(spaces);
ft_putstr("|\n");
ft_putstr("| |\n");
ft_putstr("| Result : |\n");
ft_putstr("| > ");
ft_putstr(tab[i].copy);
spaces = 26 - 4 - ft_strlen(tab[i].copy);
ft_stylebox(spaces);
ft_putstr("|\n");
ft_putstr("\\==========================/\n\n");
i++;
}
return (0);
}*/
@@ -0,0 +1,137 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_show_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/26 01:13:18 by lclerel- #+# #+# */
/* Updated: 2026/03/26 01:40:26 by lclerel- ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <unistd.h>
#include "ft_stock_str.h"
void ft_putstr(char *str)
{
int i;
if (!str)
return ;
i = 0;
while (str[i])
{
write(1, &str[i], 1);
i++;
}
}
void ft_putnbr(int nb)
{
char value;
if (nb == -2147483648)
{
write(1, "-2147483648", 11);
return ;
}
if (nb < 0)
{
write(1, "-", 1);
nb = -nb;
}
if (nb > 9)
{
ft_putnbr(nb / 10);
}
value = nb % 10 + '0';
write(1, &value, 1);
}
void ft_show_tab(struct s_stock_str *par)
{
int i;
i = 0;
while (par[i].str != 0)
{
ft_putstr(par[i].str);
write(1, "\n", 1);
ft_putnbr(par[i].size);
write(1, "\n", 1);
ft_putstr(par[i].copy);
write(1, "\n", 1);
i++;
}
}
/*
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
i++;
}
return (i);
}
char *ft_strdup(char *src)
{
int i;
int len;
char *dst;
i = 0;
len = 0;
if (src == NULL)
return (NULL);
while (src[len])
len++;
dst = malloc(sizeof(char) * (len + 1));
if (dst == NULL)
{
return (NULL);
}
while (i < len)
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (dst);
}
struct s_stock_str *ft_strs_to_tab(int ac, char **av)
{
t_stock_str *tab;
int i;
i = 0;
tab = malloc((ac + 1) * sizeof(t_stock_str));
if (!tab)
return (NULL);
while (i < ac)
{
tab[i].size = ft_strlen(av[i]);
tab[i].str = av[i];
tab[i].copy = ft_strdup(av[i]);
i++;
}
tab[i].str = av[i];
return (tab);
}
int main(int argc, char **argv)
{
t_stock_str *tab;
tab = ft_strs_to_tab(argc, argv);
if (!tab)
return (1);
ft_show_tab(tab);
return (0);
}*/