problem in this code

rohit83.ken's Avatar, Join Date: Oct 2007
Light Poster
suggestion for the correction of ths code

Code:
//Program to print a file by removing Comments
#include<stdio.h>
void main()
{
               FILE *fp;
               char ch;
               //clrscr();
               fp=fopen("temp.txt","r");
               while(1)
              {
                        ch=fgetc(fp);

                        if(ch==EOF)
                         break;
                         else
                          {
                                    if(ch=='/'){
                                     ch=fgetc(fp);
                                    if(ch=='/') 
                                    {
                                              while(1)
                                              {
                                                       ch=fgetc(fp);
                                                          if(ch=='\n')
                                                             goto label;
                                             }
                                  }
                                   if(ch=='*')
                                      { 
                                                while(1)
                                               {
                                                             ch=fgetc(fp);
                                                             if(ch=='*')
                                                                { 
                                                                             ch=fgetc(fp);
                                                                              if(ch=='/')
                                                                               {
                                                                                           while(1)
                                                                                           {
                                                                                                       ch=fgetc(fp);
                                                                                                        goto label;
                                                                                             }
                                                                                }
                                                                                else printf("*");
                                                              }
                                               }
                                    }
                                     else printf("/");                                 
                         }
                }
                     label:printf("%c",ch);
        }
           fclose(fp);
}

Last edited by shabbir; 20Oct2007 at 19:59.. Reason: Code block
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Duplicate of suggestion for correction. Thread closed.