Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mmmdreg

macrumors 65816
Original poster
Apr 14, 2002
1,393
0
Sydney, Australia
I have a uni assignment where you have to do stuff to files in C.. Currently I have it starting, the getting the filename from stdin, the doing the stuff..which all works fine..

Unfortunately, rather than putting the filename in after the program starts, I have to do it in the form "./program fileName1 fileName2" ..

Can someone please tell me briefly how to pass.. parameters to a program like that?

Cheers,

George
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
It would really help if you were familiar with the command line (Terminal). You see, many programs you invoke to be opened from the terminal can accept some arguments. The general rule for invoking a program with arguments is this:

path_to_program argument1 argument2 .. and so on. Those arguments I described will be those files you want.

Each program in C++ command-line can accept command line arguments. See this main:

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

Argc is the number of the arguments passed when invoking the program. Argv is a two dimensional array that holds those arguments. Every program has at least one argument passed. And that's it's name, accessed from argv[0], so the arguments you are going to pass manually (the files, that is) are going to be processed by accessing the argv[1] and argv[2] and... so on.

I hope I gave you a good headstart. If you have any problems, I will tell you more, but not yet, since reading any official documentation would prove more valuable for you than my advice ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.