problem in this code

Discussion in 'C' started by rohit83.ken, Oct 20, 2007.

Thread Status:
Not open for further replies.
  1. rohit83.ken

    rohit83.ken New Member

    Joined:
    Oct 19, 2007
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Oct 20, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice