CPP program to remove multi line comment from any file
This C++ program is a part of compression utility that we will create in this series of programs. This utility will help us to compress all the given files in any folder and remove all the extra spaces and new lines, tabs, comments from any executable text file.
The idea of this program was originally generated from the working of gulp. As I was not able to find out any software for desktop that is able to perform the same. We found gulp little bit boring and need a little bit learning curve is required to master its working. Here is the first program that will remove all the multi-line comment from any text file.
/* Program to remove multi-line comment from any file made by : rakesh kumar */ #include #include using namespace std; void remove_multi_comment(char source[], char dest[]){ ifstream fin(source); ofstream fout(dest); char ch; while(!fin.eof()) { fin.get(ch); if(ch=='/') { fin.get(ch); if(ch=='*') while(!fin.eof()) { fin.get(ch); if(ch=='/') break; } } else fout<<ch; } fin.close(); fout.close(); } int main() { char ch; remove_multi_comment("remove_multi_line_comment.cpp","output.cpp"); /* function call */ ifstream fin("output.cpp"); while(fin.get(ch)) cout<<ch; fin.close(); return 0; }
The name of this CPP ( remove_multi_line_comment.cpp ) file is supplied in this program as its source file, You can see the above program have some multi-line comments that our program removed successfully. We received its output in output.cpp file. The result of output file is shown here.