Datei: mem4.c


    1   /*
    2    *      mem4.c
    3    *      klin, Wed Dec 17 15:08:57 1997
    4    *      Speicherabbildung von Structs
    5    */
    6   
    7   #include <stdio.h>
    8   #include <string.h>
    9   #include <ctype.h>
   10   
   11   #define N 2
   12   #define byte unsigned char
   13   
   14   void puthex(byte *, int);
   15   
   16   struct _st {
   17     int n;
   18     char s[4];
   19   } st[N] = {
   20     0x11111111, "111",
   21     0x22222222, "222",  
   22   };
   23     
   24   void main(void)
   25   {
   26     int i;
   27       
   28     printf("Speicherabbildung von Structs\n\n");
   29     
   30     printf("s _st = %d, st = %d, a st = %p\n", sizeof(struct _st), st, &st);
   31     puthex((byte *) &st, sizeof(st));
   32     for (i = 0; i < N; i++) {
   33       printf("st[%d] a=%p n=%10d/%08x s=%s\n", i, &st[i], st[i].n, st[i].n, st[i].s);
   34       puthex((byte *) &st[i], sizeof(st[i]));
   35     }    
   36       
   37   } /* main() */
   38   
   39   void puthex(byte *s, int n)
   40   {
   41     int i;
   42     
   43     for (i = 0; i < n; i++) {
   44       printf("%02x", s[i]);
   45     }
   46     printf("\n");
   47     for (i = 0; i < n; i++) {
   48       printf("%2c", isprint(s[i]) ? s[i] : '.');
   49     }
   50     printf("\n");
   51   
   52   } /* puthex() */


Erzeugt von c2html 1.0