home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / XLIB40.ZIP / EXAMP3B.C < prev    next >
C/C++ Source or Header  |  1993-12-20  |  2KB  |  50 lines

  1. /*The following Borland C program should be linked with the assembly langauge
  2. library in EXAMP3B.ASM.  Combine the library with XLIBB.LIB using the Borland
  3. TLIB utility.  The C program first initializes XLIBB.  Next, it creates a
  4. float array.  A control block for SUMARRAY is then constructed and the call to
  5. SUMARRAY is executed.  Finally, the condition code in the control block is
  6. inspected and results are printed.*/
  7.  
  8. #include <stdio.h>
  9. #include <xlibb.h>
  10.  
  11. extern long far pascal LINADR(void far *ptr);
  12. extern void far pascal SUMARRAY(void far *ptr);
  13.  
  14. struct arraydata              /*Structure for passing arguments to SUMARRAY*/
  15. {
  16.   long condcode;
  17.   long n;
  18.   long address;
  19.   float sum;
  20. } ad;
  21.  
  22. void main(void)
  23. {
  24.   int i;
  25.   long errcode;
  26.   float a[101];
  27.  
  28.   errcode = INITXLIB();       /*Initialize XLIB*/
  29.   if (errcode != 0)           /*See if an error occurred*/
  30.   {
  31.     printf("Initialization Error:  %lX\n",errcode);
  32.     return;
  33.   }
  34.  
  35.   for(i = 0; i <= 100; i++)   /*Initialize a[]*/
  36.     a[i] = i;
  37.  
  38.   ad.condcode = 0;            /*Initialize the condition code*/
  39.   ad.n = 50;                  /*Will sum the first 50 elements in a[]*/
  40.   ad.address = LINADR(a);     /*Compute and record linear address of a[]*/
  41.  
  42.   SUMARRAY(&ad);              /*Sum the array elements*/
  43.   if (ad.condcode != 0)       /*See if an FPU error occurred*/
  44.   {
  45.     printf("Error:  %lX\n",ad.condcode);
  46.     return;
  47.   }
  48.   printf("Sum:  %f\n",ad.sum);   /*The sum should be 1225*/
  49. }
  50.