LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-21-2009, 02:54 AM   #1
lingyun
LQ Newbie
 
Registered: Jan 2008
Location: ustc
Distribution: Ubuntu
Posts: 5

Rep: Reputation: 1
Smile pass parameter in command line


How to pass parameter in command line in c++ programming?
 
Old 04-21-2009, 03:02 AM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,623

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
What????
something like this
Code:
export $LIBDIR=/usr/lib/gtk-2.6/lib
./configure --prefix=usr
what is it you want??
 
Old 04-21-2009, 03:05 AM   #3
tadeas
Member
 
Registered: Jul 2008
Location: Prague
Distribution: Opensuse
Posts: 40

Rep: Reputation: 5
Just run the executable and then the parameters after a space. For example:
Code:
./myprogram param1 param2 param3
Or do you mean how to access these parameters in the code?
 
Old 04-21-2009, 10:37 PM   #4
JohnnyBoy123
LQ Newbie
 
Registered: Apr 2009
Posts: 6

Rep: Reputation: 0
Question

(I am not a C programmer)

in script you can pass arguments explicitly as
prog arg1 arg2 arg3
and you can refer to all the arguments as $*
so I wonder if you can do
prog $*
 
Old 04-21-2009, 10:42 PM   #5
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Typically in C, your declaration of main would look something like
Code:
main(int argc, char *argv[])
You can then access the command line parameters through the array argv[i] where i = 0 to the number of parameters (argc) less 1.

Last edited by billymayday; 04-21-2009 at 10:44 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass command-line parameter to shell script? Kropotkin Linux - Newbie 12 07-25-2011 09:24 AM
[SOLVED] pass file-name as command line argument vikas027 Programming 2 10-14-2008 11:52 PM
Pass command line instructions during install? Clayton8 Linux - Newbie 7 11-07-2007 03:15 AM
how to pass the parameter to command sed linux_1 Linux - Enterprise 3 10-15-2007 07:10 PM
Awk - get a parameter from the command line benjalien Programming 1 01-24-2006 09:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration