This might be a bit of a silly question and I should probably know this anyway. I have tried searching for it but I have not found anything on this subject(or the more plausible reason, I have not been searching for the right things since I don't know much about this)

I am wondering how you can pass command line arguments to a c++ program on a mac in the form expected of

int main(int argc, char * argv[])

I have tried using terminal, going to the directory where I have the unix executable and the 2 text documents I plan to open in this program, but this is where I'm stuck.

According to the model in C++ Primer Plus the command line should look like

wc report1 report2 report3

where wc is the executable and the others the files. In my case this would be

Chapter17 test.txt test1.txt

(real original :P) which doesn't work. Any help would be greatly appreciated.

Recommended Answers

All 3 Replies

I don't use a mac but I know that wc file1 file2 works on *nix and MS-Windows. When you say "it doesn't work" what exactly do you mean. More than likely the problem is your program, not the os.

It doesn't recognize the command and throws a bash error.
However, it seems using the syntax ./wc file1 file2 does work, although I'm not entirely sure why
But thank you very much anyway :)

The . operator tells the shell to look in the current directory for the program. Without the dot the shell searches all the directories listed in your PATH environment variable for the program and executes the first one found.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.