title: How to remove an item in a file in C but keep the formatting?
body: <p>Newbie in C here. I'm working on a project that allows the user to create a to-do-list, where they can add and remove items from the list. Code as below:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  
  int row;
  void Welcome();
  void Add(row, LIST);
  void Del(row, LIST);
  void write();
  int main()
  {
     int i, j, finalrow;
     char choice;
     Welcome();
     char LIST[row][100];
     for(i = 0; i &lt; row; i++){
         printf(&quot;%d.&quot;, i+1);
         scanf(&quot;%s&quot;, &amp;LIST[i]);
     }
     write(row,LIST);
     do{
         printf(&quot;Your todolist is updated! Check it out!\n&quot;);
         printf(&quot;Wish to add item? Press A\nWish to delete item? Press D\nCool with it? Press Q\nChoice : &quot;);
         scanf(&quot;%s&quot;, &amp;choice);
         if(choice == 'A'){
             Add(row, LIST);
         } else if(choice == 'D'){
             Del(row, LIST);
         }
     } while (choice != 'Q');
  }
  
  void Welcome(){
      printf(&quot;Welcome to TO DO List Application\n&quot;);
      printf(&quot;How many item do you wish to add?\nItems: &quot;);
      scanf(&quot;%d&quot;, &amp;row);
  }
  
  void Add(int row, char TOTALLIST[row][100]){
          int newrow, j;
          printf(&quot;How many item do you wish to add?\nItems: &quot;);
          scanf(&quot;%d&quot;, &amp;newrow);
          char NEWLIST[newrow][100];
      
          for(j = 0; j &lt; newrow; j++){
              printf(&quot;%d.&quot;, j+1);
              scanf(&quot;%s&quot;, &amp;NEWLIST[j]);
              strcpy(TOTALLIST[row], NEWLIST[j]);
              row++;
          }
          write(row, TOTALLIST);
  }
  
  void Del(int row, char TOTALLIST[row][100]){ 
         int delline, i;
         printf(&quot;Which item do you wish to delete?\nRow no.: &quot;);
         scanf(&quot;%d&quot;, &amp;delline);      
         for(i = (delline - 1); i &lt; (row - 1); i++){
             strcpy(TOTALLIST[i],TOTALLIST[(i+1)]);
          }
          row--;
          write(row, TOTALLIST);
  }
  
  void write(int row, char LIST[row][100]){
      int j;
     FILE *list;
     list = fopen(&quot;TODOLIST.txt&quot;,&quot;w&quot;);
     fprintf(list,&quot;------------TO DO LIST------------\n&quot;);
     for(j = 0; j &lt; row; j++){
         fprintf(list, &quot;%d.&quot;, j+1);
         fprintf(list, &quot;%s\n&quot;, LIST[j]);
     }
  }
  </code></pre>
  <p>I have seen ways to remove item in array and how to do it in input output file as well. I have tried creating 2 files to do the removing, but as soon as I remove the line the user don't want, the numbering change. Eg.</p>
  <pre><code>1. do laundry
  2. assignments
  </code></pre>
  <p>Let's say the user removes item no.1, the output will be:</p>
  <pre><code>2. assignments
  </code></pre>
  <p>That was why I switched to this method, removing items in my char array then write it into the file, unlike the examples I have seen on internet (not sure if I'm not C99 compatible because I'm using Dev C++), the output turns out to be:</p>
  <pre><code>(remove no.1)
  1. assignments
  2. assignments
  </code></pre>
  <p>And if I throw in more than 2 items, it just becomes:</p>
  <pre><code>1.ÀúlHù
  2.^rhHù
  3.^rhHù
  </code></pre>
  <p>(p.s.: this project is not finalized yet, I know there's still alot of flaws)</p>