Display alternate characters from an existing file

Write a C program to display the alternate characters from an existing file.  

Or  

Write a C program to accept a string from user and  display the alternate  characters.


Solution:

#include<stdio.h>
#include<stdlib.h>
int main()
{
      int a=0;
      char fname[30],ch;
      FILE *fp;
      printf("\n Enter file name : ");
      gets(fname);
      fp=fopen(fname,"r");
      if(fp==NULL)
      {
            printf("\n ");
            exit(0);
      }
      ch=fgetc(fp);
      while(ch!=EOF)
      {
            if(a==0)
            {
                  printf("%c",ch);
                  a=1;
            }
            else
                  a=0;
            ch=fgetc(fp);
      }
      fclose(fp);
      return 0;
}


Output:

alternate character

Content in file.txt :

text file