Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(int argc, char const *argv[])
- {
- FILE *fin = fopen("In.cpp", "r");
- FILE *fout = fopen("Out.cpp", "w");
- bool IS_COMMENT = false;
- char readChar;
- while ((readChar = fgetc(fin)) != EOF) {
- if (IS_COMMENT) {
- if (readChar != '*') {
- // Do Nothing
- } else {
- char nextChar = fgetc(fin);
- if (nextChar == '/') {
- IS_COMMENT = false;
- }
- else {
- putc(readChar, stdout); putc(nextChar, stdout); // Debug
- fputc(readChar, fout); fputc(nextChar, fout);
- }
- }
- } else {
- if (readChar != '/') {
- putc(readChar, stdout);
- fputc(readChar, fout);
- } else {
- char nextChar = fgetc(fin);
- if (nextChar == '*') {
- IS_COMMENT = true;
- } else {
- putc(readChar, stdout); putc(nextChar, stdout); // Debug
- fputc(readChar, fout); fputc(nextChar, fout);
- }
- }
- }
- }
- fclose(fin); fclose(fout);
- printf("\n /* End of Code, Press Enter to exit. */"); getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment