This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
47 lines (44 loc) · 1.46 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.c :+: :+: */
/* +:+ */
/* By: fbes <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/11/04 16:16:54 by fbes #+# #+# */
/* Updated: 2020/11/18 16:50:20 by fbes ######## odam.nl */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
#include <stdio.h>
int main(int argc, char **argv)
{
int fd;
char **line;
int result;
if (argc > 1)
fd = open(argv[1], O_RDONLY);
else
fd = 0;
line = (char **)malloc(sizeof(char *));
*line = NULL;
if (line)
{
result = 1;
while (result > 0)
{
result = get_next_line(fd, line);
if (result >= 0)
printf("[LINE]%s\n", *line);
else if (result < 0)
printf("An error occurred; get_next_line returned -1\n");
if (*line)
free(*line);
}
free(line);
}
else
printf("Memory allocation failed!\n");
system("leaks a.out");
return (0);
}