delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/30/20:34:46

Sender: nate AT cartsys DOT com
Message-ID: <366340DF.9248C2F@cartsys.com>
Date: Mon, 30 Nov 1998 17:05:35 -0800
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.05 [en] (X11; I; Linux 2.0.35 i486)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: argv and Djgpp Yahoo club
References: <005c01be1bbf$b00d07a0$5df5ffc2 AT default> <366197D5 DOT DFD AT cam DOT org>
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019