-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
40 lines (37 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atorma <atorma@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/22 15:25:51 by atorma #+# #+# */
/* Updated: 2024/04/24 17:54:35 by atorma ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main(int argc, char **argv)
{
int i = 0;
int fd = -1;
if (argc == 2)
fd = open(argv[1], O_RDONLY);
else if (argc == 1)
fd = STDIN_FILENO;
if (fd < 0)
return (0);
char *line = NULL;
while ((line = get_next_line(fd)) != NULL)
{
printf("line[%d]: %s", i, line);
free(line);
i++;
}
close(fd);
return (0);
}