Mail Archives: djgpp/1998/11/30/20:34:46
Vic wrote:
>
> Susanne Hassing wrote:
> >
> > How do you use the argv command too make a programm like this:
> >
> > c:\>calc 21 3
> > 21-3=18
> > 21+3=24
> > 21/3=7
> > 21*3=63
>
> a=atoi(argv[1]);
> b=atoi(argv[2]);
>
> argv[1] contains 21, atoi converts a string to integer.
> the operations are as usual
> a-b
> a+b
> etc.
Note that this will make the program crash if you forget to give the
arguments. The `argc' argument to `main' tells how many arguments were
passed, which means argv[0] .. argv[argc - 1] are valid. (argv[0] is
the name of your program.) Thus, check that argc >= 3 before
continuing.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -