Test with input file

This commit is contained in:
Leonardo Algarra 2025-10-25 14:48:13 +02:00
parent aaac3125e9
commit f595a3640f
2 changed files with 17 additions and 3 deletions

2
input001 Normal file
View file

@ -0,0 +1,2 @@
/* ************************************************************************** */
/*

View file

@ -6,26 +6,38 @@
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */ /* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/22 20:50:52 by lalgarra #+# #+# */ /* Created: 2025/10/22 20:50:52 by lalgarra #+# #+# */
/* Updated: 2025/10/24 14:34:28 by lalgarra ### ########.fr */ /* Updated: 2025/10/25 13:58:21 by lalgarra ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <stdio.h> #include <stdio.h> // printf()
#include <stdlib.h> // free()
#include <fcntl.h> // open()
#include <unistd.h> // close()
#include "get_next_line.h" #include "get_next_line.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *line; char *line;
int stop; int stop;
int fd;
(void) argc; (void) argc;
(void) argv; (void) argv;
fd = 0;
if (argc > 1)
fd = open(argv[1], O_RDONLY);
if (fd < 0)
return (1);
stop = 0; stop = 0;
while (!stop) while (!stop)
{ {
line = get_next_line(0); line = get_next_line(fd);
printf("%s", line); printf("%s", line);
stop = line == NULL; stop = line == NULL;
free(line);
} }
if (fd > 0)
close(fd);
return (0); return (0);
} }