Saturday, 8 September 2012

C program for Eliminates Comment Lines

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
int main()
{
      char c;
      File *f1,*f2;
      clrscr();
      f1=fopen("C:\2026.input.c","r");
      f2=fopen("C:\2026.output.c","w");
      c=fgetc(f1);
      while(c!=EOF)
      {
                   if(c=='/'||c=='*')
                   {
                                     c=fgetc(f1);
                                     if(c=='/')
                                     {
                                               do
                                               {
                                                    c=fgetc(f1);
                                                    while(c!='/n');
                                                    }
                                                    c=fgetc(f1);
                                                    }
                                                    else
                                                    {
                                                         do
                                                         {
                                                                c=fgetc(f1);
                                                                }
                                                                while(c!='/');
                                                                c=fgetc(f1)
                                                                }
                                                                }
                                                                fputc(c,f2);
                                                                c=fgetc(f1);
                                                                }
                                                                fclose(f1);
                                                                fclose(f2);
                                                                getch();
                                                                }      

No comments:

Post a Comment