>>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.
Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343