Mail Archives: djgpp/1997/04/26/15:51:23
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 <stdio.h>
#include <stdlib.h>
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 >>> |
---------------------------------------------------------------------
- Raw text -