473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

About usage of command line arguments in another function defined out of main func

Hi,

How do i use command line arguments in the function which is called in main function and defined outside the main function.Even though,i can pass them as arguments..but if i do that...it makes me to pass many arguments.So,please let me know how do i fetch the cmnd line arguments in another function without passing them as parameters to the function.
Oct 28 '08 #1
10 1526
JosAH
11,448 Expert 8TB
Hi,

How do i use command line arguments in the function which is called in main function and defined outside the main function.Even though,i can pass them as arguments..but if i do that...it makes me to pass many arguments.So,please let me know how do i fetch the cmnd line arguments in another function without passing them as parameters to the function.
You could implement a global singleton object that holds a copy of the command
line arguments. The first thing a main() function should do is create such a single
instance. All other functions can access the instance for the value(s) of the
command line arguments.

kind regards,

Jos
Oct 28 '08 #2
donbock
2,426 Expert 2GB
How do i use command line arguments in the function which is called in main function and defined outside the main function.Even though,i can pass them as arguments..but if i do that...it makes me to pass many arguments.So,please let me know how do i fetch the cmnd line arguments in another function without passing them as parameters to the function.
The prototype for the main function is
Expand|Select|Wrap|Line Numbers
  1. int main( int argc, char *argv[]);
You can pass argc and argv to any function called from main. That's only two parameters to pass.
Oct 28 '08 #3
The prototype for the main function is
Expand|Select|Wrap|Line Numbers
  1. int main( int argc, char *argv[]);
You can pass argc and argv to any function called from main. That's only two parameters to pass.
Hi ,
the compiler gives error telling that unknowv variable..argv in the function defined out of main or which is called out frm main...Plz can u implement a prgrm..with the help of pointers.
Oct 30 '08 #4
donbock
2,426 Expert 2GB
the compiler gives error telling that unknowv variable..argv in the function defined out of main or which is called out frm main...Plz can u implement a prgrm..with the help of pointers.
Please show me
... the function prototype for the function you're trying to pass the command line arguments to.
... your function main definition (the first line of the function; the one that looks like a prototype).
... the line from within main where you call that function and pass it the command line arguments.

Make sure the prototype line occurs before the definition of the main function.
Oct 30 '08 #5
Please show me
... the function prototype for the function you're trying to pass the command line arguments to.
... your function main definition (the first line of the function; the one that looks like a prototype).
... the line from within main where you call that function and pass it the command line arguments.

Make sure the prototype line occurs before the definition of the main function.
prototype....
void getRncIpAddressAndPort( SIpta &ipta_rnc,int option,char **argv );

Function definition....sme changes are made by me....
void getRncIpAddressAndPort( SIpta &ipta_rnc,int option,char **argv )
{
int ip1oct,ip2oct,ip3oct,ip4oct ;
u32 udpport;
cout<<"the function entered"<<endl;

//cout<<"Please enter the RNC IP Address"<<endl;
char dot;
//cout<<*argv1<<endl;
do
{
cout<<"while loop entered"<<endl;
//cout<<"Valid Entry for Octets is between 0-255"<<endl;
//cin>>ip1oct>>dot>>ip2oct>>dot>>ip3oct>>dot>>ip4oct ;
if( (option == 4) || (option == 8) || (option == 9) )

{
cout<<"if loop entered"<<endl;
int Result;
//char* value;
//value = *(++argv);
//cout<<value<<endl;
if (StringToInt(++*argv), Result))
{
ip1oct = Result;
cout << "The string value is " <<*(++*argv)<< " and the int value is " << Result << endl;

}
else
{
cout << "Number conversion failed" <<endl;
}


//ip1oct = int(*(++argv));
dot = char(*(++argv));
ip2oct =int(*(++argv));
dot = char(*(++argv));
ip3oct =int(*(++argv));
dot = char(*(++argv));
ip4oct = int(*(++argv));
udpport = u32(*(++argv));

}
/* if( ((int(*argv1)) == 5) || ((int(*argv1)) == 6) )
{
ip1oct = int(*(++argv));
dot = char(*(++argv));
ip2oct =int(*(++argv));
dot = char(*(++argv));
ip3oct =int(*(++argv));
dot = char(*(++argv));
ip4oct = int(*(++argv));
udpport = u32(*(++argv));
}
if( ((int(*argv1)) == 7) || ((int(*argv1)) == 11) )
{
ip1oct = int(*(++argv));
dot = char(*(++argv));
ip2oct =int(*(++argv));
dot = char(*(++argv));
ip3oct =int(*(++argv));
dot = char(*(++argv));
ip4oct = int(*(++argv));
udpport = u32(*(++argv));

}*/
}


while ( !((ip1oct<=255)&&(ip2oct<=255)&&(ip3oct<=255)&&(ip 4oct<=255)));

SAal2sIpAddress ipAddress;

ipAddress.u.ipv4Address.ipa[0]= (u8)ip1oct;
ipAddress.u.ipv4Address.ipa[1]= (u8)ip2oct;
ipAddress.u.ipv4Address.ipa[2]= (u8)ip3oct;
ipAddress.u.ipv4Address.ipa[3]= (u8)ip4oct;

ipAddress.type = EAal2sIpAddressType_ipv4;
ipAddress.length = 4;
ipta_rnc.ipAddress = ipAddress;
//cout <<"Please enter RNC UDP Port (49152-63135)"<<endl;
//cin >> udpport ;
while( udpport<49152 || udpport>63135 )
{
cout <<"Wrong RNC UDP Port Range-(49152-63135)"<<endl;
cout <<"Please enter again RNC UDP Port with in range (49152-63135)"<<endl;
//cin>>udpport;
}

ipta_rnc.udpPort = udpport;


}
Oct 30 '08 #6
prototype....
void getRncIpAddressAndPort( SIpta &ipta_rnc,int option,char **argv );

Function definition....sme changes are made by me....
void getRncIpAddressAndPort( SIpta &ipta_rnc,int option,char **argv )
{
int ip1oct,ip2oct,ip3oct,ip4oct ;
u32 udpport;
cout<<"the function entered"<<endl;

//cout<<"Please enter the RNC IP Address"<<endl;
char dot;
//cout<<*argv1<<endl;
do
{
cout<<"while loop entered"<<endl;
//cout<<"Valid Entry for Octets is between 0-255"<<endl;
//cin>>ip1oct>>dot>>ip2oct>>dot>>ip3oct>>dot>>ip4oct ;
if( (option == 4) || (option == 8) || (option == 9) )

{
cout<<"if loop entered"<<endl;
int Result;
//char* value;
//value = *(++argv);
//cout<<value<<endl;
if (StringToInt(++*argv), Result))
{
ip1oct = Result;
cout << "The string value is " <<*(++*argv)<< " and the int value is " << Result << endl;

}
else
{
cout << "Number conversion failed" <<endl;
}


//ip1oct = int(*(++argv));
dot = char(*(++argv));
ip2oct =int(*(++argv));
dot = char(*(++argv));
ip3oct =int(*(++argv));
dot = char(*(++argv));
ip4oct = int(*(++argv));
udpport = u32(*(++argv));

}
/* if( ((int(*argv1)) == 5) || ((int(*argv1)) == 6) )
{
ip1oct = int(*(++argv));
dot = char(*(++argv));
ip2oct =int(*(++argv));
dot = char(*(++argv));
ip3oct =int(*(++argv));
dot = char(*(++argv));
ip4oct = int(*(++argv));
udpport = u32(*(++argv));
}
if( ((int(*argv1)) == 7) || ((int(*argv1)) == 11) )
{
ip1oct = int(*(++argv));
dot = char(*(++argv));
ip2oct =int(*(++argv));
dot = char(*(++argv));
ip3oct =int(*(++argv));
dot = char(*(++argv));
ip4oct = int(*(++argv));
udpport = u32(*(++argv));

}*/
}


while ( !((ip1oct<=255)&&(ip2oct<=255)&&(ip3oct<=255)&&(ip 4oct<=255)));

SAal2sIpAddress ipAddress;

ipAddress.u.ipv4Address.ipa[0]= (u8)ip1oct;
ipAddress.u.ipv4Address.ipa[1]= (u8)ip2oct;
ipAddress.u.ipv4Address.ipa[2]= (u8)ip3oct;
ipAddress.u.ipv4Address.ipa[3]= (u8)ip4oct;

ipAddress.type = EAal2sIpAddressType_ipv4;
ipAddress.length = 4;
ipta_rnc.ipAddress = ipAddress;
//cout <<"Please enter RNC UDP Port (49152-63135)"<<endl;
//cin >> udpport ;
while( udpport<49152 || udpport>63135 )
{
cout <<"Wrong RNC UDP Port Range-(49152-63135)"<<endl;
cout <<"Please enter again RNC UDP Port with in range (49152-63135)"<<endl;
//cin>>udpport;
}

ipta_rnc.udpPort = udpport;


}

its very urgent...plz...i m trying it but i m nt able to...:(
Oct 30 '08 #7
newb16
687 512MB
its very urgent...plz...i m trying it but i m nt able to...:(
Compiles on my machine. What then?
ip2oct =int(*(++argv));
I guess what it is supposed to do, but it clearly does in wrong. You advance argv to next argument string ( if it exist ), take first character of it (e.g. '1', 49 decimal and convert to unsigned char, 49?
Oct 30 '08 #8
JosAH
11,448 Expert 8TB
its very urgent...plz...i m trying it but i m nt able to...:(
Rent A Coder

kind regards,

Jos
Oct 30 '08 #9
donbock
2,426 Expert 2GB
Is this the first time you've tried to acquire and parse the command line arguments? If so, then you should concentrate on that portion of the code -- strip away everything else.
Oct 30 '08 #10
Is this the first time you've tried to acquire and parse the command line arguments? If so, then you should concentrate on that portion of the code -- strip away everything else.
thank u.....very much..:)
Oct 31 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Manlio Perillo | last post by:
Regards. In the standard library there are two modules for command line parsing: optparse and getopt. In the Python Cookbook there is another simple method for parsing, using a docstring. ...
0
by: Eric Myers | last post by:
Hello folks: (This message is also posted on the help forum at the pexpect sourceforge page, but all indentation in the code got stripped away when I submitted the post.) For some time I've...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: johny smith | last post by:
I am having trouble with a basic concept and need some help. What I want to do is upon construction of an object I want to pass in a callback function name with an argument. The class then...
7
by: qazmlp | last post by:
void func() { // Is it by anyway possible to read the value of the first command line parameter i.e. argv here ? } int main() { func() ; // No command line arguments are passed to func(). }
2
by: Bhan | last post by:
Hi, Can I get answers for the following: 1. Usage of Double Pointers during allocation memory.Heard that if memory is to be allocated by someone who is working on another module,then we...
12
by: onkar | last post by:
sometimes main accepts int main() and sometimes int main(int argc,char** argv) and sometimes int main(int argc,char **argv,char** env) still the code complies properly How is this possible ???...
4
by: Devon Null | last post by:
I have been exploring the concept of abstract classes and I was curious - If I do not define a base class as abstract, will it be instantiated (hope that is the right word) when a derived class is...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.