I have the following program :
/* a.c */
#include <stdio.h>
int
main(int argc, char* argv[]){
size_t size=0;
char* lineptr;
while(getline(&lineptr, &size, stdin)){
fprintf(stderr, "line = %s\n", lineptr);
if(lineptr){
free(lineptr);
lineptr = NULL;
}
}
return 0;
}
I redirected the output of shell command "ls" to this program using the
following line :
ls | ./a.out
Expected output :
program should print the name of all files in the current directory
and terminate.
Actual output :
The program prints the name of all the files but does not terminate,
instead it loops infinitely and prints the last entry infinitely.
Thanks
getline?int main(void).