title: How to write strings in different places of a file in C
body: <p>in the code below:</p>
  
  <pre><code>#include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  int main(int argc, char const *argv[])
  {
      FILE *fp ;
      fp = fopen("out.txt", "r+");
      int count = 1;
      char ch ;
      char userInput[5] ;
      int lineNumber = 0;
      while (lineNumber!= -1){
          fgets(userInput, sizeof(userInput), stdin);
          lineNumber = atoi(userInput);
          while((ch=fgetc(fp))!=EOF)
          {
              if(ch=='\n')  //counts number of lines
                  count++;
              if(count == lineNumber)
              {
                  fprintf(fp, "writed %d\n", count);
                  fseek(fp, 0, SEEK_SET);
              }
  
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>I want to write a string in the line which the user gives me,i store the user answer in <code>userInput</code>and then convert it to the int and store it in <code>lineNumber</code>.
  when i try to write fore example in line 90 (my file has 100 lines) two error i get:
  1.the file reduce to a 91-line file (instate of remain 100 lines)
  2.although i seek to first of file,no more lines written in the next loops and user inputs.</p>