From b4edcd7ed1478b3c7523d62bd20a87bdca1d3b0a Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Wed, 1 Jul 2020 17:40:47 +0200 Subject: [PATCH] Ex5.3 feedback: wrong wordcount due to empty lines --- ex5.3/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ex5.3/main.cpp b/ex5.3/main.cpp index 1d8ea50..d0de438 100644 --- a/ex5.3/main.cpp +++ b/ex5.3/main.cpp @@ -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; }