From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: argv[], char, and int Date: Sat, 26 Apr 1997 02:15:41 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 47 Message-ID: <3361654D.5150@SPAMcs.com> References: <5jtgo3$74r$1 AT excalibur DOT flash DOT net> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp101.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Ryan Crumley wrote: > > I am realitivly new to C/C++ and have a few questions. I am hoping someone > can give me some guidance. This is a simplified version of what I am trying > to do but hopefully it will get the point across. What I would like to do > is take argv[1], and argv[2] and preform math operations on them. This > brings up a problem because I am using "char *argv" How would I go about > changing these to an int? If anyone would be willing to help me could you > email me at the address below. /* add.c */ #include #include int main( int argc, char **argv ) { int a, b; if ( argc < 3 ) { fprintf( stderr, "Two numeric arguments required.\n" ); exit( 1 ); } a = atoi( argv[1] ); b = atoi( argv[2] ); printf( "%d + %d = %d\n", a, b, a + b ); /* etc. */ return 0; } D:\CPROGS>gcc -Wall -O -g -o add.exe add.c D:\CPROGS>add 44 55 44 + 55 = 99 D:\CPROGS> -- --------------------------------------------------------------------- | John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com | | God's final message to His Creation: | http://www.cs.com/fighteer | | "We apologize for the inconvenience."| <<< This tagline under >>> | | - Douglas Adams | <<< construction >>> | ---------------------------------------------------------------------