1
0
Fork 0

Ex5.3 feedback: use a string when reading from linebuffer

We do not know how long the words will be (except not longer than a line) so a std::string more suitable for this.
Plus, we can now use  instead of checking for a  character ourselves.
This commit is contained in:
Eric Teunis de Boone 2020-07-01 17:45:17 +02:00
parent b4edcd7ed1
commit 969ee37aa8

View file

@ -24,9 +24,6 @@ int main( int argc, char* argv[] ) {
const int bufsize = 100;
char buf[bufsize];
const int linebufsize = 10;
char linebuf[linebufsize];
// if EOF, fh returns false
while( fh ) {
fh.getline(buf, bufsize);
@ -36,10 +33,11 @@ int main( int argc, char* argv[] ) {
std::istringstream line(buf);
while( line ) {
linebuf[0] = '\0';
std::string linebuf;
line >> linebuf;
if ( linebuf[0] != '\0' ) {
if ( ! linebuf.empty() ) {
wordcount++ ;
}