title: how to write integer var to file using write() function in c
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;pthread.h&gt;
  
  void *func(void *ptr);
  int file;
  
  int main()
  {
    pthread_t thread1, thread2;
    int iret1, iret2;
    int  p;
    p=1;
  
    file=open("file1.txt", O_CREAT | O_TRUNC | O_RDWR , 0666);
    iret1 = pthread_create(&amp;thread1, NULL, func, (void *)&amp;p);
    pthread_join(thread1, NULL);
  
    close(file);
    exit(0);
  }
  
  void *func(void *ptr)
  {
    int *num;
    int i;
    num = (int *)ptr;
  
    printf("%d ", *num);
    for (i=0; i&lt;10; i++)
    {
      printf("%d", *num);
      write(file, *num, sizeof(*num));
    }
  }
  </code></pre>
  
  <p>How to write <code>integer var</code> to file using <code>write()</code> function in c? 
  This is my code. The problem is in the <code>func()</code>. If I use <code>chars</code> or <code>const int</code> it's working fine.</p>