title: Storing integers in char*
body: <p>I am a beginner is c trying something out. How can i pass an integer array to a function expecting char* in c/c++, since the range of char is only -128 to 127 but i want to store numbers from whole range of integers. </p>
  
  <p>Here is what I was trying:</p>
  
  <pre><code>#include&lt;stdlib.h&gt;
  #include&lt;stdio.h&gt;
  
  int size = 12;
  
  void print(char* array){
  
      int i,j;
      for(i=0;i&lt;size;i++)
          for(j=0;j&lt;size;j++)
              printf("%d ",*(array+i*size+j));
  
      printf("\n");
  }
  
  int main(){
  
      int array[size][size];
      int i=0,j=0,k=0;
  
      for(i=0;i&lt;size;i++)
          for(j=0;j&lt;size;j++)
              array[i][j]=k++;
  
      for(i=0;i&lt;size;i++)
          for(j=0;j&lt;size;j++)
              printf("%d ",array[i][j]);
  
      printf("\n");    
  
      print((char *) array);
  
      return 0;
  }
  </code></pre>
  
  <p>When array is printed inside the main function, the output is correct (numbers 0-143) but inside the print() function, the output is </p>
  
  <blockquote>
    <p>0 0 0 0 1 0 0 0 2 0 0 0 3 0 0 0 4 0 0 0 5 0 0 0 6 0 0 0 7 0 0 0 8 0 0
    0 9 0 0 0 10 0 0 0 11 0 0 0 12 0 0 0 13 0 0 0 14 0 0 0 15 0 0 0 16 0 0
    0 17 0 0 0 18 0 0 0 19 0 0 0 20 0 0 0 21 0 0 0 22 0 0 0 23 0 0 0 24 0
    0 0 25 0 0 0 26 0 0 0 27 0 0 0 28 0 0 0 29 0 0 0 30 0 0 0 31 0 0 0 32
    0 0 0 33 0 0 0 34 0 0 0 35 0 0 0</p>
  </blockquote>
  
  <p>I don't know what am I doing wrong.</p>
  
  <p>P.S. I need this since I am using apache Zookeeper and the set and get functions it has require arguments of type char* for your data.</p>