Example #1
0
int		ft_points(char *line, int nb_line, t_point ***array_points)
{
	char	**array_str;
	t_point	*a_point;
	int		i;

	array_str = ft_strsplit(line, ' ');
	i = 0;
	while (array_str[i] != 0)
		i++;
	if (!((*array_points) = (t_point**)malloc(sizeof(t_point) * i)))
		fdf_malloc_error();
	i = 0;
	while (array_str[i] != 0)
	{
		a_point = (t_point*)malloc(sizeof(t_point));
		a_point->x = i * SIZE_W;
		a_point->y = nb_line * SIZE_H;
		a_point->z = ft_getnbr(array_str[i]);
		a_point->s = 1;
		a_point->z_color = a_point->z;
		(*array_points)[i] = a_point;
		i++;
	}
	return (i);
}
Example #2
0
int	ft_exit(t_cmd *cmd, t_data *data)
{
  (void)data;
  g_exit_value = (cmd->next->next != cmd ? ft_getnbr(cmd->next->next->word)
		  : 0);
  ft_printf("Exit (%d)\n", g_exit_value);
  return (-1);
}
Example #3
0
int		ft_getnbr(char *str)
{
	int res;

	res = 0;
	if (str != NULL && *str == '-')
		return (-ft_getnbr(&str[1]));
	while ((*str >= '0') && (*str < +'9'))
	{
		res = (res * 10) + *str - '0';
		str++;
	}
	return (res);
}
Example #4
0
int		ft_getnbr(char *str)
{
	int nb;
	int i;

	i = 0;
	nb = 0;
	if (str[0] == '-')
		return (-ft_getnbr(&str[1]));
	while (ft_isdigit(str[i]) == 1)
	{
		nb = (nb * 10) + (str[i] - '0');
		i++;
	}
	return (nb);
}
Example #5
0
int		ft_getnbr(char *str)
{
	int		tmp;

	tmp = 0;
	if (str != NULL && str[0] == '-')
	{
		return (-ft_getnbr(&str[1]));
	}
	while ((*str >= '0') && (*str <= '9'))
	{
		tmp = (tmp * 10) + (*str - '0');
		str++;
	}
	return (tmp);
}
Example #6
0
File: main.c Project: 6Blul/42_FdF
int		main(int ac, char **av)
{
	int		**tab;
	int		fd;
	
	if (ac == 2)
	{
		fd = open(av[1], O_RDONLY);
		tab = ft_getnbr(fd);
		ft_fdf(tab);
	}
	else if (ac < 2)
		ft_putstr("Rien a lire.\n");
	else
		ft_putstr("Trop de maps !\n");
	return (0);
}
Example #7
0
void	transform_in_int(char *tmp, int *line_map, int *size_line)
{
  int	i;
  int	j;

  i = 0;
  j = 0;
  while (tmp[i])
    {
      while (tmp[i] == ' ' || tmp[i] == '\t')
	i++;
      if (tmp[i] && (tmp[i] == '0' || tmp[i] == '1'))
	line_map[j++] = ft_getnbr(&tmp[i]);
      else if (tmp[i] && tmp[i] != '0' && tmp[i] != '1')
	{
    ft_putstr("MAP ERROR.\n");
	  exit(0);
	}
      while (tmp[i] && tmp[i] != ' ' && tmp[i] != '\t')
	i++;
    }
  *size_line = j;
}
Example #8
0
int			ft_open(char *str, t_point ***t)
{
	int		fd;
	char	*line;
	int		q;
	int		count;

	count = ft_count(str);
	if (count == -1 || count == 0)
		return (-1);
	line = NULL;
	(*t) = (t_point **)malloc(sizeof(t_point *) * count);
	q = 0;
	if ((fd = open(str, O_RDONLY)) == -1)
		return (-1);
	while (get_next_line(fd, &line))
	{
		(*t)[q] = ft_getnbr(line, q);
		q++;
	}
	(*t)[0][0].y = count;
	return (0);
}
Example #9
0
File: main.c Project: Daykz/FdF
void		stock_fd(t_coor *coor)
{
	int		j;
	int		i;

	i = 0;
	coor->map = (int **)malloc(sizeof(int *) * coor->nbr_line);
	coor->len = (int *)malloc(sizeof(int) * coor->nbr_line);
	while (get_next_line(coor->fd, &(coor->line)) == 1)
	{
		j = 0;
		coor->line = all_to_space(coor->line);
		coor->split = ft_strsplit(coor->line, ' ');
		coor->len[i] = count_nbr(coor->line);
		coor->map[i] = (int *)malloc(sizeof(int) * coor->len[i]);
		while (j < coor->len[i])
		{
			coor->map[i][j] = ft_getnbr(coor->split[j]);
			j++;
		}
		i++;
		free(coor->split);
	}
}