commit
This commit is contained in:
64
C_08/git/ex05/ft_show_tab.c
Normal file
64
C_08/git/ex05/ft_show_tab.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_show_tab.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/25 10:17:09 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/25 12:05:50 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "ft_stock_str.h"
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
while (*str != '\0')
|
||||
write(1, str++, 1);
|
||||
}
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
char c;
|
||||
|
||||
if (nb < 0)
|
||||
{
|
||||
nb *= -1;
|
||||
write(1, "-", 1);
|
||||
}
|
||||
if (nb >= 0 && nb <= 9)
|
||||
{
|
||||
c = nb + '0';
|
||||
write(1, &c, 1);
|
||||
}
|
||||
else if (nb == -2147483648)
|
||||
{
|
||||
ft_putnbr((nb / 10) * -1);
|
||||
ft_putnbr((nb % 10) * -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
ft_putnbr(nb % 10);
|
||||
}
|
||||
}
|
||||
|
||||
void ft_show_tab(struct s_stock_str *par)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (par && par[i].size > 0)
|
||||
{
|
||||
ft_putstr(par[i].str);
|
||||
ft_putstr("\n");
|
||||
ft_putnbr(par[i].size);
|
||||
ft_putstr("\n");
|
||||
ft_putstr(par[i].copy);
|
||||
ft_putstr("\n");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
20
C_08/git/ex05/ft_stock_str.h
Normal file
20
C_08/git/ex05/ft_stock_str.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_stock_str.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/25 10:17:09 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/25 12:05:50 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#ifndef FT_STOCK_STR_H
|
||||
# define FT_STOCK_STR_H
|
||||
typedef struct s_stock_str
|
||||
{
|
||||
int size;
|
||||
char *str;
|
||||
char *copy;
|
||||
} t_stock_str;
|
||||
#endif
|
||||
85
C_08/git/ex05/main.c
Normal file
85
C_08/git/ex05/main.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/24 14:00:37 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/24 14:04:21 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "ft_stock_str.h"
|
||||
|
||||
void ft_show_tab(struct s_stock_str *par);
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_strdup(char *src)
|
||||
{
|
||||
char *str;
|
||||
char *_str;
|
||||
int size;
|
||||
|
||||
size = ft_strlen(src);
|
||||
str = (char *) malloc((size + 1) * sizeof(char));
|
||||
if (str == NULL)
|
||||
return (NULL);
|
||||
_str = str;
|
||||
while (*src != '\0')
|
||||
*str++ = *src++;
|
||||
*str = '\0';
|
||||
str = _str;
|
||||
return (str);
|
||||
}
|
||||
|
||||
struct s_stock_str *ft_strs_to_tab(int ac, char **av)
|
||||
{
|
||||
t_stock_str *result;
|
||||
int i;
|
||||
|
||||
result = (t_stock_str *) malloc((ac + 1) * sizeof(result));
|
||||
if (result == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (i < ac)
|
||||
{
|
||||
result[i].size = ft_strlen(av[i]);
|
||||
result[i].str = ft_strdup(av[i]);
|
||||
result[i].copy = ft_strdup(av[i]);
|
||||
i++;
|
||||
}
|
||||
result[i].size = 0;
|
||||
result[i].str = 0;
|
||||
result[i].copy = 0;
|
||||
return (result);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
t_stock_str *par;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < argc - 1)
|
||||
{
|
||||
argv[i] = argv[i + 1];
|
||||
i++;
|
||||
}
|
||||
argv[i] = NULL;
|
||||
argc--;
|
||||
par = ft_strs_to_tab(argc, argv);
|
||||
ft_show_tab(par);
|
||||
return (0);
|
||||
}
|
||||
14
C_08/git/ex05/main.sh
Executable file
14
C_08/git/ex05/main.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user