Here's another way which reads the output directly in to you're program by using _popen(). This example is running the DIR command then printing the DIR output with printf(). Then you can write to file or anything, also modify the output.
Code:
#include <stdio.h>
void Dir(char* Path)
{
char Buffer[128];
char CommandLine[128];
FILE* fin;
sprintf(CommandLine, "DIR %s", Path);
if ((fin = _popen(CommandLine, "r")) != NULL)
{
while( !feof( fin ) )
{
if( fgets( Buffer, 128, fin ) != NULL )
{
printf("My Output>>: " );
printf( Buffer );
}
}
_pclose(fin);
}
}
int main()
{
Dir("C:\\");
return 0;
}