Friday, November 25, 2011

Passing command line parameters

[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

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...