title: How to find/print the offset of a hexdump in C
body: <p>I have a block of memory represented as a collection of hex nybbles. This is viewed in a hex dump format where the value of the left column is the first two hex digits of the offset in that row. The column heading for each byte is the last digit of that offset. It looks something like this (I abbreviated some parts to save time/space):</p>
  
  <pre><code>  0  1  2  3 ..... 9  A  B .... F
  0 AD 1E 08 ......................
  1 .......
  . .......
  . .......
  9 .......
  A ....... 
  . .......
  F .......
  10.......
  11.......
  . .......
  1E.. DE
  1F.......
  </code></pre>
  
  <p>I want to go through that block of memory to a specific byte using a pointer. I then want to print the hex representation of that offset (for example, DE would be at offset 1E1). My code right now looks like:</p>
  
  <pre><code>   uint8_t *p = baseAddr;//create a pointer that points to the first byte of memory in the array
     for(int i = 0; i &lt; Length; i++){//use a for loop to move p from the start to the maximum length of the specified region 
         if(*p == Byte){//if it matches the byte you're looking for
             fprintf(Out, "%02X ", p);//print the location of the current byte
         }
         p++;
     }
  </code></pre>
  
  <p>But instead of printing out the correct value, it prints out something like "800419B1" and gives me a warning that says "format '02X' expects type 'unsigned int' but argument 3 has type 'uint8_t *'"</p>
  
  <p>Is the offset something I should be tracking as I go, or is it something I can get from the pointer? If so, how do I do it?</p>