"jagomaniak" <[EMAIL PROTECTED]> wrote:
>
> My program is run in the command line with two parameters:
>
> program -param1 param2
>
> Since I'm a beginner, I'm not sure how to do the following:
>
> I need the program to check if the param2 includes any
> characters other than capital letters (A-Z) and numbers (0-9).
> If there are other characters, the program has to print a
> message 'Second parameter includes forbidden characters.'
> and end.
#define GOOD "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
if (argv[2][strspn(argv[2], GOOD)] != 0)
{
fprintf(stderr, "Bad human...! bad human...!");
exit(EXIT_FAILURE);
}
But at face value, it's actually a poor design decision to
require that of the second parameter.
5.1.2.2.1p2 says...
"...If the host environment is not capable of supplying
strings with letters in both uppercase and lowercase,
the implementation shall ensure that the strings are
received in lowercase."
So, you should generally avoid command line arguments
being case sensitive where possible, and you should
favour lower case as the default.
--
Peter