pclose отсутствует для вашего popen.Попен это только POSIX, а не C89 / C99.Нет проверки выделения памяти в примере, это ваша работа; -)
#include <stdio.h>
#include <stdlib.h>
char **get_files(char **list)
{
FILE *fp;
char file[1000];
int i=1;
/* Open the command for reading. */
fp = popen("ls -l", "rt");
if( !fp )
perror("Failed to run command\n" ),exit(1);
while( fgets(file, sizeof file , fp) ) {
list = realloc(list, ++i * sizeof*list );
memmove( list+1, list, (i-1)*sizeof*list);
*list = strcpy( malloc(strlen(file)+1), file);
}
pclose( fp );
return list;
}
main()
{
char **files = get_files(calloc(1,sizeof*files)), **start=files;
while( *files )
{
puts(*files);
free(*files++);
}
free(start);
return 0;
}