title: Append Random Text to File (C)
body: <p>I'm trying to create a file inside a directory, then append some random text inside of the file.</p>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>char dirname[30]; 
  sprintf(dirname, "myroom.%d", (int)getpid()); 
  mkdir(dirname,0777); 
  
  char path[path_max+1];
  snprintf(path1, PATH_MAX+1, "%s/file1.txt,dirname); 
  FILE *filedir1 = fopen(path1, "a+"); 
  fclose(filedir1); 
  
  char *random_name = { "burger", "toast", "burrito", "noodles" };
  int number = rand();
  fputs(random_name[number], filedir1];
  </code></pre>
  
  <p><strong>What I want</strong></p>
  
  <p>(<em>Inside directory "dirname"</em>) </p>
  
  <p>When I open file1.txt, I expect there will be either the word burrito, burger, toast, or noodles in the first line.</p>
  
  <p><strong>What I get</strong></p>
  
  <p>file1.txt still empty.</p>
  
  <p><strong>Questions</strong></p>
  
  <p>Anybody know what happen with my code? I saw from youtube video, to append some text into a file, all I need is the fputs command but it doesn't seem to work in my code. Is it because I'm using "a+" in fopen?</p>
  
  <p>Any help will be highly appreciated. Thanks</p>