home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Collection - Online Library - January 1996 / CKITOS2196.ISO / diskette / gg244090.dsk / unc.dsk / CHAPTER.04 / MATHB_C.C < prev    next >
C/C++ Source or Header  |  1993-06-25  |  1KB  |  33 lines

  1. /******************************************************************************/
  2. /* Module  : mathb_c.c                                                        */
  3. /* Purpose : Client module for server mathb_s. Gets the values to be          */
  4. /*           added from the command line and sends them to the remote add     */
  5. /*           procedure together with the number of values passed and a        */
  6. /*           pointer to the variable that will contain the result.            */
  7. /******************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "mathb.h"
  12.  
  13. int main ( int argc, char *argv[] )
  14. {
  15.    long int i, numv, sum;
  16.    value_array_t va;
  17.  
  18.    /* Check if the user passed the minimum number of parameters.              */
  19.    if ( argc < 3 ) {
  20.       printf ( "Usage : %s <values to be added>\n", argv[ 0 ] );
  21.       exit ( 1 );
  22.    }
  23.  
  24.    /* Get values from the command line and load them in array va.             */
  25.    for ( i = 0; i < MAX_VALUES && i < argc - 1; i++ )
  26.       va[ i ] = atoi ( argv[ i + 1 ] );
  27.    numv = i;
  28.  
  29.    /* Call add passing values, number of values and pointer to result.        */
  30.    add ( va, ( long )numv, &sum );
  31.    printf( "The sum is %d\n", sum );
  32. }
  33.