title: Simple C text scanning and printing
body: <p>I am writing a very simple editor. I have it so that the program reads from stdin and then prints to stdout right now (see code below). I want a program that will take in a file, and then depending on the command either print or append more text to the file. I am still confused how to do this after reading related questions. Do I use both scanf to read the file and then printf to print into the same file? Any clarification is much appreciated.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define MAX_LINES 10
  
  char text[MAX_LINES][MAX_LINES];
  
  
  int main(void){
      FILE *infile;
      infile = fopen("file.txt", "w");
  
      //check for file
      if(infile==NULL){
          puts("Error--no file found");
          }
  
  
      int count, x, y;
      printf("Enter to quit the program.\n");
  
      for(count=1; count&lt;MAX_LINES+1; count++){
          printf("%d: ", count);
          fgets(text[count], MAX_LINES, stdin);
  
      }
  
      for(x=0; x&lt;count; x++){
          for(y=0;text[x][y];y++){
              putchar(text[x][y]);}
          putchar('\n');
      }
      fclose(infile);
      return 0;
   //end program
  }
  </code></pre>