Here some things to look over:
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char mychar;
if (argc == 2)
{
printf ("argv[1] is %s\n", argv[1]);
if (strncmp(argv[1], "-n", 2) == 0)
{
mychar = argv[1][2];
if (mychar != '\0')
printf ("found char as %c\n", mychar);
}
}
return(0);
}
/*
* When invoked with ./a.exe -nZ
argv[1] is -nZ
found char as Z
*
*/
And another sample to help you understand the layout of the command line args as they sit in memory:
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
int i, j;
for (i = 0; i < argc; i++)
for (j = 0; argv[i][j]; j++)
printf ("argv[%d][%d] is %c\n", i, j, argv[i][j]);
return(0);
}
/*
* When invoked with a.exe -nZ
argv[0][0] is E
argv[0][1] is :
argv[0][2] is \
argv[0][3] is a
argv[0][4] is .
argv[0][5] is e
argv[0][6] is x
argv[0][7] is e
argv[1][0] is -
argv[1][1] is n
argv[1][2] is Z
*
*/