title: void * function pointer
body: <p>I have made a typedef for a function pointer that takes in an integer and returns a void *:</p>
  
  <pre><code>typedef void* (*fp)(int index);
  </code></pre>
  
  <p>I then made a struct that contains a fp and another struct of the same type:</p>
  
  <pre><code>typedef struct fp_holder {
      fp function_pointer;
      iterable *next;
  } fp_holder;
  </code></pre>
  
  <p>I am trying to figure out how to call fp inside a fp_holder.</p>
  
  <p>To test this out, I did the following:</p>
  
  <pre><code>void *test_fp(int index) {
      if (index == 0) {
          printf('H');
          fflush(stdout);
          return [something_that_works];
      }
      else if (index == 1) {
          printf('e');
          fflush(stdout);
          return [something_that_works];
      }
      else if (index == 2) {
          printf('l');
          fflush(stdout);
          return [something_that_works];
      }
      else if (index == 3) {
          printf('l');
          fflush(stdout);
          return [something_that_works];
      }
      else if (index == 4) {
          printf('o');
          fflush(stdout);
          return [something_that_works];
      }
      else {
          return (void *) NULL;
      }
  }
  
  fp_holder *a = (fp_holder *) malloc(sizeof(fp_holder));
  a-&gt;function_pointer = test_fp;
  a-&gt;next = NULL;
  </code></pre>
  
  <p>So with all that setup, I tried to call a's function_pointer by trying the following:</p>
  
  <pre><code>a-&gt;function_pointer(0);
  (*a-&gt;function_pointer)(0);
  ((*)a-&gt;function_pointer)(0);
  </code></pre>
  
  <p>I just cannot figure out why those are not working.
  Help would be appreciated! :)</p>
  
  <p>EDIT</p>
  
  <p>What I am trying to do:
  Call a's function_pointer with an argument.</p>
  
  <p>I will try out some answers right now and see what happens.</p>
  
  <p>EDIT2</p>
  
  <p>Answered! I was calling it right by doing a->function_pointer(0) but what was giving me a segmentation error [which is what my issue was - and maybe I should have clarified this] was the printf statement and NOT my call. printf needs a string not the char as I put in.</p>