[sourcecode language="cpp"]
#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;
}
[/sourcecode]
No comments:
Post a Comment