>> If you're searching for files, it's usually easier to use functions that search for files rather than having to mess around with string parsing
That won't recurse a directory, though. There are a few cross-platform libraries that can do this, including boost::filesystem.
If you want to parse the output of the command, you'll need to use 'popen' instead of 'system', ie:
Code:
#include <stdio.h>
int main( void )
{
int
success = 0;
size_t
read = 0;
const size_t
size = 1024;
char
buffer[ size + 1 ];
const char*
command = "dir /b | findstr /c:\".RPT\" ";
FILE*
pipe = popen( command, "r" );
if( pipe )
{
for( ;; )
{
read = fread( buffer, 1, size, pipe );
if( read == 0 )
break;
success = 1;
buffer[ read ] = 0;
printf("Buffer:\n***\n%s\n***\n", buffer );
if( read < size )
break;
}
pclose( pipe );
}
if( !success )
{
fprintf( stderr, "Error: could not not execute command: %s\n", command );
return 1;
}
return 0;
}