title: C program to get first word of each line from a .txt file and print that word onto another .txt file: Kind of works but also prints random letters
body: <p>So we have this file called dictionary1.txt and it has words with their pronounciation right next to them. What I want to do is to get the first word from each line and print them onto another txt file that the program creates from scratch. My code does it but it also prints random Chinese letters in between English words, I don't know why.</p>
  
  <p>Here's what the ouput file looks like: <a href="https://imgur.com/a/pZthP" rel="nofollow noreferrer">https://imgur.com/a/pZthP</a></p>
  
  <p>(Pronounciations are seperated from the actual words in each line with a blankspace in dictionary1.txt)</p>
  
  <p>My code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char *argv[]) {
  char line[100];
  int i = 0;
  FILE* fp1 = fopen("dictionary1.txt", "r");
  FILE* fp2 = fopen("dictionary2.txt", "w");
  
  if (fp1 == NULL || fp2 == NULL){
      printf("ERROR");
      return -1;
  }
  
  while (fgets(line, 100, fp1) != NULL){
      while (line[i] != ' '){
          fputc(line[i], fp2);
          i++;
      }
      i=0;
      fputc('\0', fp2);
  }
  
  return 0;
  }
  </code></pre>
  
  <p>I tried fputc('\n', fp2) as well bu t no matter what I couldn't get onto the next line in the file I created from scratch. I also can't get rid of all the random Chinese letters.</p>
  
  <p>EDIT: I figured it out. The .txt file I was working on was saved in Unicode formatting, which didn't work well with my program. I turned it into ANSI and now it works like a charm.</p>