Ex5.3 feedback: wrong wordcount due to empty lines
This commit is contained in:
parent
2c33d4246c
commit
b4edcd7ed1
1 changed files with 7 additions and 2 deletions
|
@ -36,8 +36,13 @@ int main( int argc, char* argv[] ) {
|
||||||
|
|
||||||
std::istringstream line(buf);
|
std::istringstream line(buf);
|
||||||
while( line ) {
|
while( line ) {
|
||||||
|
linebuf[0] = '\0';
|
||||||
line >> linebuf;
|
line >> linebuf;
|
||||||
wordcount++ ;
|
|
||||||
|
if ( linebuf[0] != '\0' ) {
|
||||||
|
wordcount++ ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( line.eof() )
|
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;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue