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.

78 lines
1.7 KiB
C
Raw Normal View History

2023-08-03 23:16:27 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fst_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/01 18:23:55 by axdubois #+# #+# */
/* Updated: 2023/08/02 11:28:35 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/utils-h/utils.h"
int ft_len_line(int file, int n)
{
int count;
char *buf;
int i;
i = 0;
while (i < n)
{
read(file, &buf, 1);
i++;
}
count = 0;
buf = malloc(1);
while (*buf != '\n' && read(file, &buf, 1) > 0)
count++;
free(buf);
close(file);
return (count);
}
int ft_len_colum(int file)
{
int count;
char *buf;
int i;
i = 0;
count = 0;
buf = malloc(1);
while (read(file, &buf, 1) > 0)
{
if (*buf == '\n')
count++;
}
free(buf);
close(file);
return (count);
}
char *ft_get_first_line(int file)
{
char *buf;
int i;
char *fst_line;
int len_line;
//if (file == -1) main
//return (-1);
len_line = ft_len_line(file, 0);
fst_line = malloc(len_line + 1);
if (fst_line == NULL)
return (NULL);
i = 0;
while (i < len_line)
{
read(file, &buf, 1);
fst_line[i] = *buf;
i++;
}
fst_line[i] = 0;
return (fst_line);
}