Hello guys. I want to compare two files using a system call to DOS command fc. The problem is that fc does not open the file entered as a command line argument.

code = system("fc args[1] ..\\o.txt");

Does anybody know how to make it work?

It's interpreting args[1] literally in the string, there's no translation that will take place. Make a C++ string out of "fc "+(string)args[1]+" ..\\o.txt" then pass that in as mystring.c_str() to system().

You can't pass the filename like that, that's just passing "args[1]" as a string literal you need to do something like this:

// build the string..
std::string command = "fc " + (std::string)args[1] + " ../o.txt";

// now execute the command..
code = system(command.c_str());

Now you're good to go!
Cheers for now,
Jas.

EDIT: Dammit, I knew I shouldn't have gone out to put the kettle on before hitting submit!

Edited 6 Years Ago by JasonHippy: n/a

It's interpreting args[1] literally in the string, there's no translation that will take place. Make a C++ string out of "fc "+(string)args[1]+" ..\\o.txt" then pass that in as mystring.c_str() to system().

Thanks a lot. It works now :)

You can't pass the filename like that, that's just passing "args[1]" as a string literal you need to do something like this:

// build the string..
std::string command = "fc " + (std::string)args[1] + " ../o.txt";

// now execute the command..
code = system(command.c_str());

Now you're good to go!
Cheers for now,
Jas.

EDIT: Dammit, I knew I shouldn't have gone out to put the kettle on before hitting submit!

Thanks a lot. It works now :)

This article has been dead for over six months. Start a new discussion instead.