How am i able to pass multiple arguments in a C program like this, using different switches
program -d <argument1> -p <argument2>
I'm using getopt to enable me to pass arguments.
int main(int argc, char **argv)
{
while(1)
{
unsigned int c = getopt(argc, argv, "-dD:hHgGp:");
if( c == -1 ) break;
switch( c )
{
case 'D':
case 'd':
printf("\nd=");
strcpy(D,optarg);
printf(D);
break;
case 'g':
case 'G':
printf("g");
break;
case 'p':
printf("\nPath=");
strcpy(pathFile,optarg);
printf(pathFile);
break;
case 'H':
case 'h':
usage(); //For help
return 0;
default:
return 0;
}
}
}
EDIT: The code here is a dummy code which I use for testing. It returns the argument that is passed as a string.