title: segmentation fault in file operations in c
body: <pre><code>#include&lt;stdio.h&gt;
  
  /* this is a lexer which recognizes constants , variables ,symbols, identifiers , functions , comments and also header files . It stores the lexemes in 3 different files . One file contains all the headers and the comments . Another file will contain all the variables , another will contain all the symbols. */
  
  int main()
  {
      int i;
      char a,b[20],c;
      FILE *fp1;
  
      fp1=fopen("source.txt","r"); //the source file is opened in read only mode which will passed through the lexer
  
      //now lets remove all the white spaces and store the rest of the words in a file 
  
      if(fp1==NULL)
      {
          perror("failed to open source.txt");
          //return EXIT_FAILURE;
      }
      i=0;
      while(1)
      {
  
  
          a=fgetc(fp1);
  
          if(a !="")
          {
              b[i]=a;
          }
          else
          {
  
  
              fprintf(fp1, "%.20s\n", b);
              i=0;
              continue;
          }
          i=i+1;                  
  
          /*Switch(a)
          {
              case EOF :return eof;
              case '+':sym=sym+1;
  
              case '-':sym=sym+1;
  
              case '*':sym=sym+1;
  
              case '/':sym=sym+1;
  
              case '%':sym=sym+1;
  
              case '
          */
      }
  return 0;
  }
  </code></pre>
  
  <p>how does this code end up in segmentation fault?</p>