title: How do I generate concatenated fibonacci numbers in C?
body: <p>Task is that function needs to print first n fibonacci nums in a new string:Example,for n = 10 function returns string "11235813213456"..Not sure why is this not totally working</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  char* Fibonacci(int n)
  {
      char s[50];
      char *x = malloc(1000);
      int f1 = 0, f2 = 1, i;
  
      for (i = 1; i &lt;= n; i++)
      {
          sprintf(s, "%d ", f2);
          strcat(x,s);
          int next = f1 + f2;
          f1 = f2;
          f2 = next;
      }
      return x;
  }
  
  int main(void)
  {
      char* fib = Fibonacci(10);
      printf("%s\n", fib);
      free(fib);
  
      return 0;
  }
  </code></pre>