+ Reply to Thread
Results 1 to 2 of 2

Thread: Write a C program to remove comments from any C program

  1. #1
    Surfer is offline Senior Member
    Join Date
    Mar 2010
    Posts
    321

    Write a C program to remove comments from any C program

    Write a C program to remove comments from any C program. It should remove single and multi line comments.

  2. #2
    Surfer is offline Senior Member
    Join Date
    Mar 2010
    Posts
    321
    Code:
    #include <stdio.h>
    
    int main(int argc, char** argv)
    {
    	FILE *fp;
    	char ch;
    	fp=fopen("sub.c","r");
    	ch=getc(fp);
    	while(ch!=EOF) {
    		if(ch=='/') {
    			ch=getc(fp);
    			if(ch=='/') {
    				while((ch=getc(fp))!='\n') {
    					getc(fp);//This commment wil be removed
    				}
    			}
    			if(ch=='*')/*This also wil be removed*/ {
    				while(1) {
    					ch=getc(fp);
    					if(ch=='*') {
    						ch=getc(fp);
    						if(ch='/') {
    							break;
    						}
    					}
    				}
    			}
    		}
    		printf("%c",ch);
    		ch=getc(fp);
    	}
    	return 0;
    }

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 13th February 2012, 17:48
  2. Write output of given program
    By TopGun in forum Microsoft
    Replies: 3
    Last Post: 13th June 2011, 22:27
  3. Replies: 1
    Last Post: 19th July 2010, 22:31
  4. Output of the program
    By Surfer in forum C++ Fundamentals
    Replies: 1
    Last Post: 23rd April 2010, 11:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts