removing comments of type // and /*

rohit83.ken's Avatar, Join Date: Oct 2007
Light Poster
please help me in writing the code that takes a c or c++ file and deletes the comments and prints the output to other file

totally 3 files r involved
one removes the comments
other is the program having comments
other is output printed without any comments containing c or c++ code

prethanks to the helper

kindly send the source code or provide link
DaWei's Avatar, Join Date: Dec 2006
Team Leader
This is not a free software store. You should either

1) Attempt to write the code and ask here for help with your problems.
2) Put your request in the Job Offers forum.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
I can share the algo with you.

Parse the characters of the file and check for // or /* but remember that they should not be under the string literal ""

Now if you find // which is not under the string literal then ignore the line
if you find /* and its not in the string literal then ignore till */
Else you write everything to the new file.

I hope it helps.