ft_strs_to_tab.c
This commit is contained in:
commit
d7c041eacf
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/30 23:45:06 by tosuman #+# #+# */
|
||||||
|
/* Updated: 2023/03/30 23:45:08 by tosuman ### ########.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
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_boolean.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/30 23:47:26 by tosuman #+# #+# */
|
||||||
|
/* Updated: 2023/03/30 23:47:26 by tosuman ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_BOOLEAN_H
|
||||||
|
# define FT_BOOLEAN_H
|
||||||
|
# include <unistd.h>
|
||||||
|
# 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 FALSE 0
|
||||||
|
# define TRUE 1
|
||||||
|
# define SUCCESS 1
|
||||||
|
|
||||||
|
typedef char t_bool;
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_abs.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/31 00:06:36 by tosuman #+# #+# */
|
||||||
|
/* Updated: 2023/03/31 00:06:37 by tosuman ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_ABS_H
|
||||||
|
# define FT_ABS_H
|
||||||
|
# define ABS(Value) (Value > 0 ? Value : -Value)
|
||||||
|
#endif
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_point.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/31 00:10:28 by tosuman #+# #+# */
|
||||||
|
/* Updated: 2023/03/31 00:10:29 by tosuman ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_POINT_H
|
||||||
|
# define FT_POINT_H
|
||||||
|
|
||||||
|
typedef struct s_point
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} t_point;
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,78 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strs_to_tab.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/03/31 00:56:37 by tosuman #+# #+# */
|
||||||
|
/* Updated: 2023/03/31 00:56:38 by tosuman ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "ft_stock_str.h"
|
||||||
|
|
||||||
|
int ft_strlen(char *str)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
while (*str++)
|
||||||
|
++size;
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_strcpy(char *str)
|
||||||
|
{
|
||||||
|
char *copy;
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
copy = malloc(sizeof(char) * (ft_strlen(str) + 1));
|
||||||
|
idx = 0;
|
||||||
|
while (*str)
|
||||||
|
copy[idx++] = *str++;
|
||||||
|
copy[idx] = 0;
|
||||||
|
return (copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct s_stock_str *ft_strs_to_tab(int ac, char **av)
|
||||||
|
{
|
||||||
|
int idx;
|
||||||
|
t_stock_str *tab;
|
||||||
|
|
||||||
|
tab = malloc(sizeof(t_stock_str) * (ac + 1));
|
||||||
|
idx = -1;
|
||||||
|
while (++idx < ac)
|
||||||
|
{
|
||||||
|
tab[idx].size = ft_strlen(av[idx]);
|
||||||
|
tab[idx].str = av[idx];
|
||||||
|
tab[idx].copy = ft_strcpy(av[idx]);
|
||||||
|
}
|
||||||
|
tab[idx].str = 0;
|
||||||
|
return (tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ////
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
char *strs[4];
|
||||||
|
t_stock_str *tab;
|
||||||
|
|
||||||
|
strs[0] = "First";
|
||||||
|
strs[1] = "Second";
|
||||||
|
strs[2] = "Third";
|
||||||
|
tab = ft_strs_to_tab(3, strs);
|
||||||
|
printf("tab[0] element size:%d, str:'%s' (%p), copy:'%s' (%p)\n",
|
||||||
|
tab[0].size, tab[0].str, tab[0].str, tab[0].copy, tab[0].copy);
|
||||||
|
printf("tab[1] element size:%d, str:'%s' (%p), copy:'%s' (%p)\n",
|
||||||
|
tab[1].size, tab[1].str, tab[1].str, tab[1].copy, tab[1].copy);
|
||||||
|
printf("tab[2] element size:%d, str:'%s' (%p), copy:'%s' (%p)\n",
|
||||||
|
tab[2].size, tab[2].str, tab[2].str, tab[2].copy, tab[2].copy);
|
||||||
|
printf("tab[3] element size:%d, str:'%s' (%p), copy:'%s' (%p)\n",
|
||||||
|
tab[3].size, tab[3].str, tab[3].str, tab[3].copy, tab[3].copy);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
*/ ////
|
Loading…
Reference in New Issue