-
Prelude's code with modification
Code:
#include <cctype>
...
while ( inFile.get ( c ) ) {
cout<< c;
if ( c == '\n' ) {
linecount++;
charcount = 0; // it's a new line so let's start counting from zero again
}
else if ( !isspace ( c ) )
charcount++;
}
-
Just count the characters in one line, when you reach \n simply output whatever message you see fit, and set charCount = 0; ready for the next line.
If you're having trouble, post your latest code.
Tip: Don't use this code to control a loop:
while (!inFile.eof())
It's a bad habbit. There's an explanation of why here:
http://faq.cprogramming.com/cgi-bin/...&id=1043284351
That's a C FAQ, but the principle still stands. You can code your way out of it and still use eof(), but its better not to.
[edit]
Doh! Didn't see alphaoide's last message :rolleyes:
-
:D Yeah!!! I think I can do this. Thanks a tera-bunch for helping me out.
Fudd's law states: "What goes in must come out." Aside from being patently untrue, Fudd's law neglects to mention that what comes out need not bear any resemblence to what went in.
-V. Orehck III (ficticious)