home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / CLIB / UT_DMEM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  1.3 KB  |  56 lines

  1. /*********************
  2.  *
  3.  *  ut_dmem.c - dump memory in hex and ASCII.
  4.  *
  5.  *  Purpose: This file contains a function to dump memory in hex and
  6.  *           ASCII.
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985,1989 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include <stdio.h>
  14. #include "blackstr.h"
  15.  
  16.  
  17. /********
  18.  *
  19.  *   ut_dump(memptr,nbytes) - dump memory to std output
  20.  *
  21.  **/
  22.  
  23. void ut_dump(
  24.     char  *memptr,                    /* Pointer to start of memory to dump   */
  25.     int   nbytes)                     /* Number of bytes to dump              */
  26.  
  27. {
  28.     int   i;                          /* Line counter                         */
  29.     int   j;                          /* Bytes on line (<= 16) counter        */
  30.     int   k;                          /* Byte counter = 16*i + j              */
  31.     int   n;                          /* Number of lines to output            */
  32.  
  33.     n = nbytes/16 + 1;
  34.  
  35.     for (i = 0; i < n; i++) {
  36.     for (j = 0; j < 16; j++) {
  37.         k = 16*i + j;
  38.         if (k < nbytes)
  39.         printf("%02x ", memptr[k]);
  40.         else
  41.         printf("   ");
  42.         }
  43.     printf("   ");
  44.     for (j = 0; j < 16; j++) {
  45.         k = 16*i + j;
  46.         if (k < nbytes) {
  47.         if (memptr[k] >= 0x20 && memptr[k] <= 0x7e)
  48.             printf("%c", memptr[k]);
  49.         else
  50.             printf(".");
  51.             }
  52.         }
  53.     printf("\n");
  54.     }
  55. }
  56.