1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
42-1st-piscine/ended/rush02/ex00/ft_parse_line.c
2023-08-06 20:12:38 +02:00

63 lines
1.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_parse_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: julemart <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/31 15:38:42 by julemart #+# #+# */
/* Updated: 2022/07/31 15:40:22 by julemart ### ########.fr */
/* */
/* ************************************************************************** */
#include "rush02.h"
char *ft_addchar(char *str, char c)
{
char *return_val;
int i;
i = 0;
while (str[i++])
;
return_val = malloc(i + 2);
i = 0;
while (str[i] != '\0')
{
return_val[i] = str[i];
i++;
}
return_val[i++] = c;
return_val[i] = '\0';
free(str);
return (return_val);
}
struct s_nb ft_parse_line(char *line)
{
struct s_nb result;
int i;
result.nbr = malloc(1);
result.txt = malloc(1);
i = 0;
if (line[0] < '0' || line [0] > '9')
return (result);
while (line[i] >= '0' && line[i] <= '9')
{
result.nbr = ft_addchar(result.nbr, line[i]);
i++;
}
while (line[i] == ' ')
i++;
i++;
while (line[i] == ' ')
i++;
while (line[i] != '\n')
{
result.txt = ft_addchar(result.txt, line[i]);
i++;
}
return (result);
}