get_next_line/src2/test.c
Willem Haffmans 0e894b1b63 add all
2024-07-26 22:30:53 +02:00

54 lines
888 B
C

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int fd;
char *line;
if (argc > 1)
fd = open(argv[1], O_RDONLY);
else
fd = STDIN_FILENO;
if (fd < 0)
{
return (1);
}
while ((line = get_next_line(fd)) != NULL)
{
printf("%s", line);
free(line);
}
close(fd);
return (0);
}
/*
#include <stdio.h>
int main(int argc, char **argv)
{
int fd;
char *line;
if (argc > 1)
fd = open(argv[1], O_RDONLY);
else
fd = STDIN_FILENO;
if (fd < 0)
{
return (1);
}
line = get_next_line(fd);
printf("1: first char: %s\n", *line++ == '\n' ? "true" : "false");
printf("1:second char is \\0: %s\n", *line == '\0' ? "true" : "false");
line = get_next_line(fd);
printf("line is null: %s\n", line == NULL ? "true" : "false");
printf("2: first char is \\0: %s\n", *line == '\0' ? "true" : "false");
close(fd);
return (0);
}
*/