commit
This commit is contained in:
@@ -1,9 +1,20 @@
|
|||||||
#ifndef FT_STOCK__STR_H
|
/* ************************************************************************** */
|
||||||
# define FT_STOCK__STR_H
|
/* */
|
||||||
typedef struct s_stock_str
|
/* ::: :::::::: */
|
||||||
|
/* 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;
|
int size;
|
||||||
char *str;
|
char *str;
|
||||||
char *copy;
|
char *copy;
|
||||||
} t_stock_str;
|
} t_stock_str;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,22 +1,64 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_point.h :+: :+: :+: */
|
/* s_stock_str.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */
|
/* Created: 2021/08/25 10:17:09 by gbaconni #+# #+# */
|
||||||
/* Updated: 2021/08/20 12:05:50 by gbaconni ### ########.fr */
|
/* Updated: 2021/08/25 12:05:50 by gbaconni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef FT_POINT_H
|
#include <stdlib.h>
|
||||||
# define FT_POINT_H
|
#include "ft_stock_str.h"
|
||||||
|
|
||||||
typedef struct s_point
|
int ft_strlen(char *str)
|
||||||
{
|
{
|
||||||
int x;
|
int i;
|
||||||
int y;
|
|
||||||
} t_point;
|
i = 0;
|
||||||
void set_point(t_point *point);
|
while (str[i] != '\0')
|
||||||
#endif
|
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 = av[i];
|
||||||
|
result[i].copy = ft_strdup(av[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
result[i].size = 0;
|
||||||
|
result[i].str = 0;
|
||||||
|
result[i].copy = 0;
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,16 +10,30 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include "ft_stock_str.h"
|
#include "ft_stock_str.h"
|
||||||
|
|
||||||
struct s_stock_str *ft_strs_to_tab(int ac, char **av);
|
struct s_stock_str *ft_strs_to_tab(int ac, char **av);
|
||||||
|
|
||||||
int main(void)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
t_stock_str *result;
|
t_stock_str *result;
|
||||||
char **av;
|
int i;
|
||||||
int ac;
|
|
||||||
|
|
||||||
result = ft_strs_to_tab(ac, av)
|
(void) result;
|
||||||
|
i = 0;
|
||||||
|
while (i < argc - 1)
|
||||||
|
{
|
||||||
|
argv[i] = argv[i + 1];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
argc--;
|
||||||
|
result = ft_strs_to_tab(argc, argv);
|
||||||
|
i = 0;
|
||||||
|
while (result[i].size > 0)
|
||||||
|
{
|
||||||
|
printf("result[%d] = { size=%d, str=%s, copy=%s}\n", i, result[i].size, result[i].str, result[i].copy);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user