title: Write int variable in file using write
body: <p>I'm currently trying to write an integer variable using write function in the file. This is my code:</p>
  
  <pre><code>int main(int argc, char** argv){
  int fd, nbMult, i;
  char buf[4];
  if((fd = open("data", O_CREAT|O_RDWR, 0777))==-1){
      perror("ERROR\n");
      exit(EXIT_FAILURE); 
  }
  
  do{ 
      printf("Bla bla ");
      if( scanf("%d", &amp;nbMult) !=1 ) while( (i = getchar()) != '\n' );
  }while(nbMult&lt;1);
  sprintf(buf, "%d", nbMult);
  if( write(fd, buf, sizeof(int)) == -1 ){
      perror("ERROR\n");
      exit(EXIT_FAILURE);
  }
  
  close(fd);
  return 0; }
  </code></pre>
  
  <p>It creates the file, but when I try to open it, it shows me "cannot display ". When I remplace the name of the file by data.txt it works but it shows strange character in the file. I have tried also to convert the Integer variable to String using sprintf() and it's the same issue.</p>