Skip to main content
10 of 13
deleted 18 characters in body

I found a easy solution!

cpp -P yourcommentedfile.txt 

SOME UPDATES:

Quote from the user ilkachu (original text from the user comments):

I played a bit with the options for gcc: -fpreprocessed will disable most directives and macro expansions (except #define and #undef apparently). Adding -dD will leave defines in too; and std=c89 can be used to ignore new style // comments. Even with them, cpp replaces comments with spaces (instead of removing them), and collapses spaces and empty lines.

But i think it is still reasonable and a easy solution for the most of the cases, if you disable the macro expansion and other things i think you will get good results... - and yes you can combine that with shell script for getting better... and much more...

I am personally using cpp -P (without any other parameter) for removing comments from php files without any problem for years.

If that is not enough for you, try stripcmt - a comment remover: http://www.bdc.cx/software/stripcmt/