-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
48 lines (42 loc) · 1.35 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: agras <agras@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/02 18:34:55 by agras #+# #+# */
/* Updated: 2024/03/27 19:48:56 by agras ### ########.fr */
/* */
/* ************************************************************************** */
#include <fcntl.h>
#include <stdio.h>
#include "get_next_line.h"
void printf_file(int fd)
{
char *line;
while (1)
{
line = get_next_line(fd);
if (line == NULL)
break ;
printf("%s", line);
free(line);
}
}
int main(int ac, char **av)
{
if (ac < 2)
{
printf("Usage: %s <file>\n", av[0]);
return (1);
}
int fd = open(av[1], O_RDONLY);
if (fd == -1)
{
printf("Error: Cannot open file %s\n", av[1]);
return (1);
}
printf_file(fd);
return (0);
}