title: C a program to backup dot files
body: <p>So I've written a small program to keep updating my dotfiles in another directory with a git repository. I just wanted to keep practising my C coding.</p>
  
  <p>The program is a gross violation of the DRY principle and does not work either.
  Here is the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  
  int main(void)
  {
      FILE *files_from[7];
      files_from[0] = fopen(".vimrc", "r");
      files_from[1] = fopen(".profile", "r");
      files_from[2] = fopen(".tmux_conf", "r");
      files_from[3] = fopen(".zshrc", "r");
      files_from[4] = fopen(".bashrc", "r");
      files_from[5] = fopen(".bash_aliases", "r");
      files_from[6] = fopen(".gitconfig", "r");
  
      FILE *files_to[7];
      files_to[0] = fopen("dotFiles/.vimrc", "w");
      files_to[1] = fopen("dotFiles/.profile", "w");
      files_to[2] = fopen("dotFiles/.tmux.conf", "w");
      files_to[3] = fopen("dotFiles/.zshrc", "w");
      files_to[4] = fopen("dotFiles/.bashrc", "w");
      files_to[5] = fopen("dotFiles/.bash_aliases", "w");
      files_to[6] = fopen("dotFiles/.gitconfig", "w");
  
  
      for(int i = 0; i &lt; 7; ++i)
      {
          int character;
          while( (character = fgetc(files_from[i])) != EOF)
          {
              fputc(character, files_to[i]); 
          }
      }
  
  
  
  }
  </code></pre>
  
  <p>Why do I get a segmentation fault ?!
  (Also anyway to keep it DRY?)</p>
  
  <p>EDIT: You are all right. One of them was NULL. I just added an if statement before the while loop to check if the current file from either array is NULL.</p>
  
  <p>NOW how can I make this DRY?</p>