title: C Programming: convert int* to char*
body: <p>I understand that I cannot convert an int* into a char* but must copy the int* into a char* array using sprintf. My issue is that I believe I am using sprintf correctly but I am getting this warning:
  warning: passing argument 1 of ‘sprintf’ from incompatible pointer type. Here is a condensed and simplified version of what I am trying to do. </p>
  
  <pre><code>int* iarray = calloc(top + 1, sizeof(int));
  char* carray = (char*)calloc(count,sizeof(char));
  /*
  some code that adds stuff to the int*, it works fine....something like
  for(i=0; i&lt;=count; i++)
      iarray[i] = i;
  lets assume that iarray is something like 1234
  */
  for(i=0; i&lt;=count; i++)
  {
      sprintf(carray, "%d", iarray[i]);
      printf("%s", carray) //this is just to test, it only prints out the first number...
  }
  </code></pre>
  
  <p>This has been driving me nuts... If you want more of my code then please let me know.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: here is more code. I skipped the basic variable declarations, I can add those in but I assure you all those are fine</p>
  
  <p>Here is a function to do the conversion:</p>
  
  <pre><code>void ints_to_chars(char* carray, int count, int* iarray)
  {
      //convert ints to char*
      int i;
      //char *char_array=(char*)calloc(count,sizeof(char));
      printf("ints to chars: char array--&gt;");
      for(i=0; i&lt;=count; i++)
      {
          sprintf(carray, "%d", iarray[i]);
          printf("%s",carray);
      }
      return;
  }
  
  int main(int argc, char** argv)
  {
  int i, j, count;
  
  if(i-1 == 0)
                    bottom = 2;
                else
                    bottom = (int)atoi(argv[i-1])+1;
                top = (int)atoi(argv[i]);
                printf("child %d: bottom=%d, top=%d\n", getpid(), bottom, top);
  
                prime_iarray = calloc(top + 1, sizeof(int));
                primenumbers(prime_iarray,bottom,top);
                count = prime_iarray[0];
  
                /*printf("prime int array: \n");
                for(i=1; i&lt;=count; i++)
                {
                    printf("%d", prime_iarray[i]);
                }*/
  
                //int* into char*
                prime_carray = (char*)calloc(count,sizeof(char));
                ints_to_chars(prime_carray, count, prime_iarray);
                printf("prime char array:\n");
                printf("%s",&amp;prime_carray[0]);
  
  }
  </code></pre>
  
  <p>EDIT 2: So someone kindly pointed out a silly error that removed the warning I was getting. But my char* only prints out the first character.... I initially was returning a local char* but found out that that will always only return the first character. What am I doing wrong? Can someone explain to me why this is happening? I'm sorry, I'm new to pointers and I'm really struggling with this...</p>