i was having a problem with my file handling homework...
this is our homework...
Write a program that outputs its own C++ source file to a file called "WithoutComments.cpp" and to the screen, but omitting any of the comments enclosed in "/* ... */" markers (and omitting the markers themselves). The new program in the file "WithoutComments.cpp" should compile and run in exactly the same way as the program from which it was generated.
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
main()
{ /*every function should start with an open curly brace to indicate the starting of the func*/
char c; /*declaration of char c*/
ifstream file1; /*connects the ifstream "file1" to a following file.*/
ofstream file2;
file1.open("nyl.cpp");
file2.open("withoutcomments.cpp");
file1.get(c);
while(!file1.eof()){
cout<<c;
file2.put(c);
file1.get(c);
}
file2.close();
file1.close();
return 0;
}
MY PROBLEM IS THAT I CANT FIND ANY BUILT-IN FUNCTIONS THAT COUD OMIT ANY MARKER AND THE STATEMENTS THAT ARE INCLOSED TO IT.....
A short pseudo-code to help you out. It is best to code this by yourself so you'd understand better.
1 2 3 4 5 6 7
if current character is '/' or '*'{
if previous character is '/'
skip all characters until '*' or '\n'
}
if current character is '*' and next character is not '/'
repeat skip