title: Is there a way to pass printf letter (%c, %d) as a function argument?
body: <p>Please consider the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void printStrGeneric(void *, int, int);
  void printNumGeneric(void *, int, int);
  
  int main()
  {
  
      int intArray[] = { 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85 };
  
      printNumGeneric(intArray, sizeof(intArray), sizeof(int));
      printStrGeneric(intArray, sizeof(intArray), sizeof(int));
      puts("");
  
      short shortArray[] = { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74 };
  
      printNumGeneric(shortArray, sizeof(shortArray), sizeof(short));
      printStrGeneric(shortArray, sizeof(shortArray), sizeof(short));
      puts("");
  
      return 0;
  }
  
  void printStrGeneric(void *object, int size, int elem_size)
  {
      char *p = (char *) object;
      while (p &lt; (char *) object + size) {
          printf("%c\t", *p);
          p += elem_size;
      }
      puts("");
  }
  
  void printNumGeneric(void *object, int size, int elem_size)
  {
      char *p = (char *) object;
      while (p &lt; (char *) object + size) {
          printf("%d\t", *p);
          p += elem_size;
      }
      puts("");
  }
  </code></pre>
  
  <p>– given that the functions <code>printStrGeneric</code> and <code>printNumGeneric</code> are almost identical (except for the <code>printf</code> letter), I wonder whether it is in any way possible to have just 1 function instead, and pass a <code>printf</code> letter (either <code>%c</code> or <code>%d</code>) to the function as an argument?</p>