>>The code I have written so far works, but it prints the entire code
If it prints the entire code then it doesn't work, does it.
line 8: this is a c++ program, so replace the char array with std::string, which will allow you to enter a file name of any length up to the limit set by the operating system.
Line 16: if the file name contains spaces then that line will not work. Safer if you use getline().
lines 30-37: not a good way to detect eof. Don't read the file one character at a time -- that's too much work. Here's a simpler way to do this
std::string line;
while( getline(InStream,line) )
{
std::string::size_type pos = line.find("//");
if(pos != std::string::npos)
{
std::string word = line.substr(pos);
cout << word;
}
}
This doesn't solve the /**/ type comments but should work the // style commens.
This was not compiled or tested, so use the above at your own risk. Last edited by Ancient Dragon; Apr 26th, 2007 at 10:22 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Offline 21,963 posts
since Aug 2005