-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
54 lines (51 loc) · 1.67 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
49
50
51
52
53
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ashongwe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/24 14:04:52 by ashongwe #+# #+# */
/* Updated: 2019/06/29 06:38:41 by ashongwe ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <sys/types.h>
#include "get_next_line.h"
#include "libft/libft.h"
int main(int argc, char **argv)
{
int fd;
int ret;
int line1;
char *line;
line1 = 0;
if (argc == 2)
{
fd = open(argv[1], O_RDONLY);
while ((ret = get_next_line(fd, &line)) > 0)
{
printf("[Return: %d] Line #%d: %s\n", ret, ++line1, line);
free(line);
}
//printf("[Return: %d] Line #%d: %s\n", ret, ++line1, line);
if (ret == -1)
printf("Error\n");
else if (ret == 0)
printf("End of file\n");
close(fd);
}
if (argc == 1)
{
while ((ret = get_next_line(0, &line)) > 0)
printf("[Return: %d] Line #%d: %s\n", ret, ++line1, line);
if (ret == -1)
printf("Error\n");
else if (ret == 0)
printf("End of stdin\n");
close(fd);
}
return (0);
}