title: I've a text file. The text file contains strings. I wanna remove space from end of the sentence by using C programming
body: <p>There is some question regarding my question but I can not find the exact answer from those related questions. That's why I'm asking. Please try to understand and provide me a Function by which I will be able to get the correct answer. </p>
  
  <p>I've a text file. Say it's "filename.txt" 
  The file contain some strings. And at the end of every sentence there is a extra space. </p>
  
  <p><strong>For Example: The input file:</strong></p>
  
  <pre><code>high blood sugar levels (space)
  type 2 diabetes definition (space)
  high blood sugar symptoms 
  glucose tolerance test 
  symptoms of high blood sugar 
  </code></pre>
  
  <p>Here after every sentence there is an extra space. I would like to remove those spaces.</p>
  
  <p><strong>I want to generate a output file like this:</strong></p>
  
  <pre><code>high blood sugar levels,
  type 2 diabetes definition,
  high blood sugar symptoms,
  glucose tolerance test,
  symptoms of high blood sugar
  </code></pre>
  
  <p>I've tried this, but the space is still before comma(,). </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      fopen("out.txt", "w", "stdout");
      char ch, keywords[25];
      FILE *fp;
  
      fp = fopen("keywords.txt","r"); // read mode
  
      if( fp == NULL )
      {
          perror("Error while opening the file.\n");
          exit(EXIT_FAILURE);
      }
  
      printf("The contents of %s file are :\n", "keywords.txt");
  
      while( ( ch = fgetc(fp) ) != EOF )
      {
          if(ch=='\n') ch=',';
          printf("%c",ch);
      }
  
      fclose(fp);
      return 0;
  }
  </code></pre>
  
  <p>Please also guide me, How to print my result to a output file. I will use this simple program for my personal task. That's why I'm trying to find the result. Please help me. </p>