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

s7on3d

macrumors newbie
Original poster
Jun 9, 2007
12
0
Hi everyone,
I'm pretty new to my mac, and also relatively new to programming... First year engineering student :)
I've written the following program as a command line program in C with Xcode:

int main(int argc, char *argv[]) // MAIN FUNCTION!!
{
int i;
for (i=0;i<argc;i++)
{
printf("argv[%d]: %s\n",i,argv);
}
return 0;
}

Which should receive input as a set of strings from the command line when the program is run, then print it back out.

My question is how do I run the program (I assume from the terminal...) and pass on the parameters (in this case just a sentence)?

After quite a bit of playing around I've managed to successfully reach the right directory in the terminal, and open the program (using the "open" command), but I can't work out how to send it the parameters...

Thanks in advance,
Ilan
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
You shouldn't use open. That will run the program via launch services and is unlikely to preserve command line arguments. You should simply do what you would do on any other Unix system: supply the full path to the command you want to execute (in this case your program). If you are in the same folder as the executable then ./<your program name> will run the program.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.