The program is written in C. :) I have the parameters check in my
program already, I'm just struggling with how to write that loop.

char *c = argv[2];

while (*argv[2])
{
  if ((isupper(*argv[2])) || (isdigit(*argv[2])))
  { continue; }
  else
   printf("Second parameter includes forbidden characters");
   return EXIT_FAILURE;
}

But that doesn't work.


--- In [email protected], "David Hamill" <[EMAIL PROTECTED]> wrote:
>
> > My program is run in the command line with two parameters:
> >
> > program -param1 param2
> 
> This is a C answer, it may be slightly different in C++.
> 
> If you declare
> 
>   int main(int argc, char *argv[])
> 
> you should first check that argc == 3 and exit with a 
> suitable error message if not. With argc ==  3, you can 
> access argv[0] (program name), argv[1] (param1 string), 
> argv[2] (param2 string).
> 
> BTW argc and argv can have any names you like but these are 
> the conventional ones (for argument count and argument 
> vector).
> 
> > I need the program to check if the param2 includes any 
> > characters
> > other than capital letters (A-Z) and numbers (0-9).
> 
> Loop through argv[2] until you reach the terminating '\0', 
> applying the "is" functions of <ctype.h> to each char. Or 
> you could do it the long way and compare each char with 'a', 
> 'z', '0', '9'.
> 
> Good luck!
> 
> David
>



Reply via email to