I know this works as expected if your command line arguments are strings.
#include <stdio.h>
int main( int argc, char *argv[] )
{
printf("Program name %sn", argv[0]);
if( argc == 2 )
{
printf("The argument supplied is %sn", argv[1]);
}
else if( argc > 2 )
{
printf("Too many arguments supplied.n");
}
else
{
printf("One argument expected.n");
}
}
Would you be able to do something similar to this if you have integers or would you need to use the first method then convert it with atoi?
#include <stdio.h>
int main( int argc, int *argv[] )
{
printf("Program name %sn", argv[0]);
if( argc == 2 )
{
printf("The argument supplied is %sn", argv[1]);
}
else if( argc > 2 )
{
printf("Too many arguments supplied.n");
}
else
{
printf("One argument expected.n");
}
}