title: How to copy string without allocating memory - C
body: <p>I just started in C and this is a beginner question. But is there any way to copy a string without allocating memory beforehand?
  I want to reproduce the strcopy function inbuilt in C with the same structure (<code>char *strcpy(char *src, char *dest);</code>). I got it to work with declaring the char pointer in the function itself and then returning it. It works also with the original structure as strcpy if I allocate the memory beforehand.</p>
  <pre><code>#include &lt;stdlib.h&gt;
  
  char *strcopy(char *src, char *dest)
  {
      int i = 0;
      while (src[i] != '\0')
      {
          dest[i] = src[i];
          i++;
      }
      dest[i] = '\0';
      return (dest);
  }
  
  int str_size(char *str)
  {
      int i = 0;
      while (str[i] != '\0')
          i++;
      return (i);
  }
  
  int main(int argc, char **argv)
  {
      char *src = argv[1];
      char *dest = (char*)malloc(str_size(src));
      dest = strcopy(src, dest);
      return (0);
  }
  </code></pre>
  <p>So is it somehow possible to copy a string without allocating memory beforehand and without changing my function-head?</p>