[Insight-users] [switch structure] within a command-line app

Luis Ibanez luis.ibanez@kitware.com
Mon, 07 Apr 2003 22:57:58 -0400


Hi Joris,

The easy way to do a switch statment with command line
arguments is to provide an integer in the command line,
and convert the corresponding string to an integer
using "atoi()"


Something like:


int main(int argc, char * argv[] )
{

const int option = atoi( argv[1] );
switch( option )
{
   case 1:
     // instantiate MeanSquares
     break;
   case 2:
     // instantiate MutualInformation
     break;
   default:
     //  Unkown metric
     return -1;
}


--------


Regards,


    Luis


----------------------
J Mst wrote:
> Hi all,
> 
> I was trying to build a program which could include several different 
> configurations of a registration procedure. I was inspirated by the 
> ImageRegistration example from the InsightApplications dir.
> 
> I tried to build a sortlike program but now in the command line. The 
> example uses switch statements in order to pass the correct metric or 
> optimizer etc... The whole application I built compiles well except for 
> the part where I use these switch statements.
> 
> VC++ gives me an error saying  I cant use a switch statement using a * 
> char as input. I looked in the VC help and I found that the switch 
> statement has to have an int as input. I was confused because I saw in 
> the example that a char type was used is input for the switch.
> 
> I did the following thigs:
> --------------------------------------
> typedef enum{
> MutualInformation,
> MeanSquares,
> ...etc
> } metricIdentifier
> 
> metricIdentifier   m_selectedMetric;
> 
> m_selectedMetric = argv[4];
> 
> switch (m_selectedMetric){
> case MutualInformation:
> { registration->SetMetric( MutualInformationMetric )
>  break;
> }
> etc for other cases.
> --------------------------------------------------
> 
> So it gives an error with the argv input I think. I have no idea how I 
> should build an good switch structure with a argv as input.
> 
> Any help would be greatly appreciated.
> 
> Joris
> 
> 
> 
> 
> 
> _________________________________________________________________
> Chatten met je online vrienden via MSN Messenger. http://messenger.msn.nl/
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>