OK,
here's what I did.
I set i to point to the first element. then, I ran a loop that would run from 
the top of i, to the bottom.
what you did, is set i to point to the beginning of the string in argv[2], and 
then ran a while loop while (*i)
As you never increment or decrement *i, your program will just hang if i is 
true. what you need to do, is print a message if an invalid char has been hit, 
and break.
Then, increment *i (*i++), and in your while loop, set it to:
while (*i!='\0')
HTH,

Thanks,
Tyler Littlefield
email: [EMAIL PROTECTED]
web: tysdomain-com
Visit for quality software and web design.
skype: st8amnd2005

  ----- Original Message ----- 
  From: jagomaniak 
  To: [email protected] 
  Sent: Saturday, November 08, 2008 6:22 AM
  Subject: [c-prog] Re: Command line parameters


  I'm sorry, I don't understand your code. I'm getting really desperate,
  because we even haven't learnt all this stuff at school yet. 

  --- In [email protected], "Tyler Littlefield" <[EMAIL PROTECTED]> wrote:
  >
  > you need to assign a pointer to it like:
  > char*i=argv[2];
  > then do something like:
  > for (int counter=0;counter<strlen(i);counter++)
  > {
  > if (foo(i[counter]))
  > ...
  > etc. Code may be a bit messy, I'm still half asleep.
  > 
  > Thanks,
  > Tyler Littlefield
  > email: [EMAIL PROTECTED]
  > web: tysdomain-com
  > Visit for quality software and web design.
  > skype: st8amnd2005
  > 
  > ----- Original Message ----- 
  > From: jagomaniak 
  > To: [email protected] 
  > Sent: Saturday, November 08, 2008 4:58 AM
  > Subject: [c-prog] Re: Command line parameters
  > 
  > 
  > 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" <david@> 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
  > >
  > 
  > 
  > 
  > 
  > 
  > [Non-text portions of this message have been removed]
  >



   

[Non-text portions of this message have been removed]

Reply via email to