title: How to access union inside structure?
body: <p>I have the following code:</p>
  
  <pre><code>/* sample.c */ 
      #include&lt;stdio.h&gt; 
      #include&lt;malloc.h&gt; 
      #include&lt;stdlib.h&gt; 
      #include"hermes.h" 
      #include&lt;string.h&gt; 
  
      int main (){
          struct hermes *h ;
          h = ( struct hermes *) malloc ( sizeof ( struct hermes *));
  
          strcpy ( h-&gt;api-&gt;search_response-&gt;result_code , "123" );
              printf("VALue : %s\n" , h-&gt;api-&gt;search_response-&gt;result_code );
          return 0; 
      }
  
  /* hermes.h */ 
      struct hermes {
  
       union  {
  
            /* search response */
                      struct  {
                              int error_code;
                              char *result_code;
                              char *user_track_id;
                              struct bus_details bd;
                      }*search_response;
  
          }*api;
      };
  </code></pre>
  
  <p>I get a segmentation fault when I try to access the elements. Could anyone tell me what is the right way to access these elements?</p>