title: Function with string as return type in C
body: <p>I needed a function to return a string. I used the following code to declare the function:</p>
  
  <pre><code>const char* serv_con(char app_data[50])
  {
      char send_data[1024],recv_data[1024];
      //i am avoiding code segments irrelevant to the issue.
      return recv_data;
  }
  </code></pre>
  
  <p>and then called the function in the main like this:</p>
  
  <pre><code>int main()
  {
      char ser_data[50], app_data[50];
      ser_data[0] = '\0';
      app_data[0] = '\0';
      //avoiding code segments irrelevant to the issue.
      app_data = serv_con(ser_data); //function call
  }
  </code></pre>
  
  <p>On compiling it gives the error:</p>
  
  <pre><code>connect.c:109: error: incompatible types when assigning to type ‘char[50]’ from type ‘const char *’
  </code></pre>
  
  <p>Then i replaced the <em>const char</em> in the declaration with std::string. The declaration now is as follows:</p>
  
  <pre><code>std::string serv_con(char app_data[50])
  {
      char send_data[1024],recv_data[1024];
      //avoiding code segments irrelevant to the issue.
      return recv_data;
  }
  </code></pre>
  
  <p>And called it in the same way as mentioned above. But still it gives the following error on compiling:</p>
  
  <pre><code>connect.c:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
  </code></pre>
  
  <p>Please tell me how I can give a string as a return type from a function. The platform I work on is linux. Thanks in advance.</p>