The pro way is to use pipes.
But if you're looking for a simple way, you could direct the output of the called program to a file. (Here I'm assuming you're on windows since you used the term "command prompt".)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char *name = tmpnam(NULL);
if (!name)
return EXIT_FAILURE;
char command[L_tmpnam + 10] = "dir > ";
strcat(command, name);
system(command);
char line[BUFSIZ];
FILE *f = fopen(name, "r");
while (fgets(line, sizeof line, f)) {
if (strstr(line, "<DIR>"))
fputs(line, stdout);
}
fclose(f);
remove(name);
return 0;
}