Part 1
int main(int argc, char **argv)
{
int fd;
int i;
char *line;
if (!(fd = open(argv[1], O_RDWR | O_CREAT)))
{
printf("Error in open\n");
return (0);
}
while ((i = get_next_line(fd, &line)) > 0)
{
printf("%i-%s\n",i, line);
free(line);
}
printf("%i-%s",i, line);
free(line);
}
Part 2
int main(int argc, char **argv)
{
int fd;
int i;
char **line;
if (!(fd = open(argv[1], O_RDWR | O_CREAT)))
{
printf("Error in open\n");
return (0);
}
while ((i = get_next_line(fd, line)) > 0)
{
printf("%i-%s\n",i, *line);
free(*line);
}
printf("%i-%s",i, *line);
free(*line);
}
Is there any difference between Part 1 and Part 2, the difference between them is one use **line
and another just *line
.
From my understanding, both should be the same.
I am using them to test my own implementation of a function that reads and return 1 line.
The problem:
Part 1 test works fine. Part 2 testing results in segmentation fault
The implementation of get_next_line()
remain same for both.