home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / util / super_c / histclib.c < prev    next >
Encoding:
Text File  |  1980-01-01  |  1.9 KB  |  49 lines

  1. /*              Histogram Library; C portion.
  2.  */
  3.  
  4. /*      prHist(hist)
  5.  
  6.         Function: Given a pointer to a table of 1025 histogram counters,
  7.         print out the address that each counter covers, the count for that
  8.         counter, and the percentage of the total both with and without
  9.         the "other" counter included. Don't print counters that are zero.
  10.  
  11.         Algorithm: Add up all the counters. Print out the heading. Then
  12.         cycle through all the counters, printing out the information.
  13. */
  14.  
  15. prHist(hist)
  16.  
  17. long *hist;
  18.  
  19. {
  20.         float total, totalWo;
  21.         long *hptr;
  22.         unsigned addr;
  23.  
  24.         /* Alert the user that we're done running, and are now computing
  25.            the histogram. */
  26.         printf("Program done. Compiling histogram data.\n\n");
  27.         /* Add up all the counters. */
  28.         for (total = 0, hptr = hist+1; hptr < hist+1025; total += *hptr++);
  29.         /* Compute the total without the "other" category. */
  30.         totalWo = total + ((float) *hist);
  31.         /* Print the total count without "other." */
  32.         printf("Total recorded hits: %15.0f.\n\n",totalWo);
  33.         /* Print the header for the main list. */
  34.         printf(" Address     Count    %% with Other  %% without Other\n");
  35.         printf("---------  ---------  ------------  ---------------\n");
  36.         /* Print the "other" counter. */
  37.         printf("  Other    %9ld      %7.3f%%\n",*hist,
  38.                100.0*(((float) *hist)/total));
  39.         /* Loop through all of the counters... */
  40.         for (hptr = hist+1, addr = 0; hptr < hist+1025; hptr++, addr += 64)
  41.                 /* If it isn't zero, print it. */
  42.                 if (*hptr != 0L)
  43.                         printf("%4x-%4x  %9ld      %7.3f%%         %7.3f%%\n",
  44.                                addr,addr+63,*hptr,
  45.                                100.0*(((float) *hptr)/totalWo),
  46.                                100.0*(((float) *hptr)/total));
  47. }
  48.  
  49.