title: string updating in c
body: <p>this is a sample program demonstrating getting a string value from a func</p>
  
  <ol>
  <li>can allocate memory inside called function itself and return</li>
  <li>can allocate memory inside calling function and called function just updates it.</li>
  </ol>
  
  <p>i am facing problem with the 2nd way.
  is there any workaround?</p>
  
  <pre><code>/*
   * main.c
   *
   *  Created on: Sep 6, 2014
   *      Author: Murtaza
   */
  #include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  char* someFunc1();
  void someFunc2(char* str);
  void firstApproach();
  void secondApproach();
  int main()
  {
      firstApproach();
      printf("\n");
      secondApproach();
      return 0;
  }
  char* someFunc1()
  {
      char *str = (char*)malloc(sizeof(char)*10);
      str = "HELLO";
      return str;
  }
  void someFunc2(char* str)
  {
      str = "Hello";
  }
  void secondApproach()
  {
      char *str = (char*)malloc(sizeof(char)*10);
      someFunc2(str);
      printf(str);
      printf("heythere");
  }
  void firstApproach()
  {
      char *str;
      str=someFunc1();
      printf(str);
      printf("wassup");
  }
  </code></pre>
  
  <p>Please tell me why the second approach isn't working.
  thanks!
  my output is:</p>
  
  <pre><code>HELLOwassup
  h&gt;heythere
  </code></pre>
  
  <p>and my expected output should be</p>
  
  <pre><code>HELLOwassup
  Helloheythere
  </code></pre>