Line 14. "/" is a legitimate C++ operator, not a comment. You'll be treating "8 / 2" as a partial comment. You have at minimum 4 tokens: "//", /*", "*/", "\n". Three of them are multi-character, so your code is going to have to be more complex than reading in a character and looking at it.
You have at least 3 states, key phrase is "at least". Get the algorithm down first with pencil and paper before you even start with the program.
1. C++ code.
2. Within a "//" comment.
3. Within a "/*" comment.
The tokens are paired and have a hierarchy. "//" comments are not parsed within a "/*" comment, so you stop looking for "//" and "\n" if you are between a "/*" and a "*/".
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
It also helps to comment your own code. Then you can use it to test itself.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Time to back up...
Read a line
Search for // then /*
If you found one of them, process that comment style.
If you found both, which one's first? Process that one only.
If you get a // the rest of the line is a comment -- done.
If you get a /* search for */ -- everything between is a comment
-- if */ not found, read another line and search again. Keep it up until you've found it.
Remember, this is legal:
if (val /*the number being tested*/ != 0 /*has a good value*/ (
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
So when you find a / read the next character.
1) If it's a *, read until */
2) If /, read until EOL
3) If neither, continue on.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944