54 lines
888 B
C
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);
|
|
}
|
|
|
|
*/ |