1
0
Fork 0

Ex5.3 feedback: wrong wordcount due to empty lines

This commit is contained in:
Eric Teunis de Boone 2020-07-01 17:40:47 +02:00
parent 2c33d4246c
commit b4edcd7ed1
1 changed files with 7 additions and 2 deletions

View File

@ -36,8 +36,13 @@ int main( int argc, char* argv[] ) {
std::istringstream line(buf);
while( line ) {
linebuf[0] = '\0';
line >> linebuf;
wordcount++ ;
if ( linebuf[0] != '\0' ) {
wordcount++ ;
}
if ( line.eof() )
{
@ -48,5 +53,5 @@ int main( int argc, char* argv[] ) {
}
std::cout << " " << linecount-1 << " " << wordcount-1 << " " << charcount-1 << " " << argv[1] << std::endl;
std::cout << " " << linecount-1 << " " << wordcount << " " << charcount-1 << " " << argv[1] << std::endl;
}