logic problem

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

  1. rohit83.ken

    rohit83.ken New Member

    Joined:
    Oct 19, 2007
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    //removes comments from the file and prints to the other file

    Code:
    #include<stdio.h>
    void main(int argc,char *argv[])
    {
    	FILE *in,*out;
    	
    	char ch1,ch2;
    	
    	int f=0;
    	
    	in=fopen(argv[1],"r");
    	
    	out=fopen(argv[2],"w");
    	
    	while(!feof(in))
    	{
    		ch1=getc(in);
    		
    		if(ch1=='/')
    		{
    			
    			if((ch2=getc(in))=='/')
    			{
    				
    				while((ch2=getc(in))!='\n')
    				{
    					;
    				}
    			}
    			
    			else
    			
    			if(ch2=='*')
    			{
    				
    				while((ch2=getc(in))!=EOF)
    				{
    					
    					if(ch2=='*')
    					{
    						if((ch2=getc(in))=='/')
    						f=1;
    					}
    					
    					if(f==1)
    					break;
    				}
    			}
    		}
    		
    		else
    		{
    			putc(ch1,out);
    		}
    	}
    	fclose(in);
    	fclose(out);
    } 
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    The above solution is not complete. It does not take into account when you have statement like

    Code:
    cout<<"/* Please enter your choice */"<<endl;
     

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