title: How to cast a string to a function pointer in C?
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/1118705/call-a-function-named-in-a-string-variable-in-c">call a function named in a string variable in c</a><br>
    <a href="https://stackoverflow.com/questions/801070/dynamically-invoking-any-function-by-passing-function-name-as-string">Dynamically invoking any function by passing function name as string</a>  </p>
  </blockquote>
  
  <p>I have certain functions.. say,</p>
  
  <pre><code>double fA1B1C1( .. ) {
           ...
  }
  
  double fA2B2C3( .. ) {
           ...
  }
  
  double (*fptr)( .. );
  
  fptr myfunc;
  </code></pre>
  
  <p>These functions are already defined. </p>
  
  <p>So when the user inputs the string "A2B2C2", it is got into a variable and converted to "fA2B2C2"</p>
  
  <pre><code>myfunc = formatted_string; // DOES NOT WORK
  </code></pre>
  
  <p>But the above syntax does not work. Even typecasting it does not work.</p>
  
  <pre><code>myfunc = (fptr) formatted_string // DOES NOT WORK
  </code></pre>
  
  <p>But if I hard code it as</p>
  
  <p><code>myfunc = fA2B2C2</code> (or) <code>myfunc = &amp;fA2B2C2</code>, it works pefectly.</p>
  
  <p>Where am I going wrong?</p>
  
  <p>EDIT::</p>
  
  <pre><code>I tried creating a hash table and a lookup function. Like
  
  create_hashEntry(hashtable, string, formatted_string);
  // string = "A1B1C1; formatted_string = "fA1B1C1"
  </code></pre>
  
  <p>then the look up function</p>
  
  <pre><code>myfunc lookup_func(char *string) {
         return(get_hashEntry(hahstable, string));
  }
  </code></pre>
  
  <p>This also failed to work.</p>