02: Integers and strings

Decimal and octal integers

The GNU C Reference Manual

The GNU C Reference Manual

Example program

#include <stdio.h>
#include <stdlib.h>


int main( int argc, char** argv ) {

/*
 * "12" is one representation of the number 12
 * "XII" is another representation of the number 12
 *  014 is the octal representation of 12
*/

/*
 average distance of planets from sun
 mercury:   57 million km.
 venus:    108 million km.
 earth:    150 million km.
 mars:     228 million km.
 jupiter:  779 million km.
 
 saturn;  1.43 billion km.
 uranus:  2.88 billion km.
 neptune: 4.50 billion km.
*/


    printf( "I am here.\n" );

    printf( "argc = %2d\n", argc );
    printf( "planet = %s\n", argv[0] );
    printf( "planet = %s\n", argv[1] );
    printf( "planet = %s\n", argv[2] );
    printf( "planet = %s\n", argv[3] );
    printf( "planet = %s\n", argv[4] );

    // "atoi" means "alphanumeric to integer"
    // atoi translates a string to an integer
    int mercuryDistance = atoi( argv[1] );
    int venusDistance = atoi( argv[2] );
    int earthDistance = atoi( argv[3] );
    int marsDistance = atoi( argv[4] );

    printf( "distance between first two planets: %d\n",
        venusDistance - mercuryDistance );

    printf( "here is twelve: %d\n", 014 );
    printf( "here is twelve in octal: %o\n", 12 );

    exit( 0 );
} // main( int, char** )