-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
59 lines (50 loc) · 1.93 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
55
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hmstrx <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/12 09:14:39 by aperez-b #+# #+# */
/* Updated: 2025/01/10 17:11:35 by hmstrx ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
#include <stdio.h>
#include <fcntl.h>
#include <limits.h>
int main()
{
//==========================================bonus test==========================================
int fd1;
int fd2;
int i = 1;
fd1 = open("tests/J. K. Rowling - Harry Potter 1 - Sorcerer's Stone.txt", O_RDONLY);
fd2 = open("tests/the-king-james-bible.txt", O_RDONLY);
char *buf;
while ((buf = get_next_line(fd1)) != NULL)
{
printf("Line %d for fd %d: %s", i, fd1, buf);
free(buf);
i++;
}
printf("\n---------------------------\n");
i = 1;
while ((buf = get_next_line(fd2))) {
printf("Line %d for fd %d: %s", i, fd2, buf);
free(buf);
i++;
}
close(fd1);
close(fd2);
//==========================================mandatory test==========================================
int fd = open("main.c", O_RDWR);
char *line = get_next_line(fd);
while (line)
{
printf("%s", line);
free(line);
line = get_next_line(fd);
}
close (fd);
}