title: Print/store n bytes of u_char pointer in c?
body: <p>I am trying to make a function to print/store the first n bytes of an u_char pointer. This is what I currently have (just trying to print the first value), but it doesn't work.</p>
  
  <pre><code>void print_first_value(const u_char * p) {
      printf("%d", p[0]);
  }
  </code></pre>
  
  <p>I have also tried this:</p>
  
  <pre><code>void print_first_value(const u_char * p) {
      printf("%d", &amp;p[0]);
  }
  </code></pre>
  
  <p>How would I make this work? In the end I want to loop through the individual values in <code>*p</code>, but I can only print the entire string at the address pointed to by <code>p</code> via this code.</p>
  
  <pre><code>void print_first_value(const u_char * p) {
      printf("%s", p);
  }
  </code></pre>
  
  <p>So what I am printing out is packets, sorry I didn't mention that. The last snippet of code prints a packet in hex, so something like <code>0050 5686 7654 0000...</code> and I want to print/store the values at certain indexes. So I want the first two blocks <code>00505686</code>, then the next two and so on.</p>