LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 03: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, 04:02 AM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,817

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
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, 04: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, 11: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, 11: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 11:44 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10:24 AM
[SOLVED] pass file-name as command line argument vikas027 Programming 2 10-15-2008 12:52 AM
Pass command line instructions during install? Clayton8 Linux - Newbie 7 11-07-2007 04:15 AM
how to pass the parameter to command sed linux_1 Linux - Enterprise 3 10-15-2007 08:10 PM
Awk - get a parameter from the command line benjalien Programming 1 01-24-2006 10:06 AM


All times are GMT -5. The time now is 02:20 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration