title: Write char[128] array to file in C
body: <p>I wrote a program to test writing a char[128] array to file using write() function in C. The following is my code, however, after writing, I can see that the string "testseg" is followed by a "d" or "È" in the testFile.txt file. Is this a proper way of writing char[] array to file?</p>
  
  <pre><code>int main()
  {
      char pathFile[MAX_PATHNAME_LEN];
      sprintf(pathFile, "testFile.txt");
      int filedescriptor = open(pathFile, O_RDWR | O_APPEND | O_CREAT, 0777);
  
      int num_segs = 10;
      int mods = 200;
      const char *segname = "testseg";  /* */
      char real_segname[128];
      strcpy(real_segname, segname);
  
      write(filedescriptor, &amp;num_segs, sizeof(int));
      write(filedescriptor, real_segname, strlen(real_segname));
      printf("real_segname length is %d \n", (int) strlen(real_segname));
      write(filedescriptor, &amp;mods, sizeof(int));
  
      close(filedescriptor);
  
  
      return 0;
  }
  </code></pre>