RSS

Passing command line parameters

25 Nov
 #include <iostream>
 using namespace std;
 int main( int argc, char **argv )

{

//for taking command line arguments
bool numFound=false;
char myCharArray[10];
int x=argc;
int y;
cout <<"You entered  "<<x-1  <<" parameters after the command \"commandLine.\""<<endl;
cout <<"They were:  ";
for (int i=1; i<x; i++)
{
strcpy(myCharArray, argv[i]);
cout <<myCharArray<<"  ";
}

cout<<endl;
for (int i=1; i<x; i++)
{
strcpy(myCharArray, argv[i]);
if(isdigit(myCharArray[0]))
{

if(numFound==false)
cout<<"The number(s) you entered were:  ";

numFound=true;
y=atoi(argv[i]);
cout <<y<<" ";

}

}

cout <<endl;

}


 
Advertisements
 
Leave a comment

Posted by on November 25, 2011 in C++

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: