May 2012
Intermediate to advanced
679 pages
16h 56m
English
We have discussed exiting loop with function eof() in section 14.4.5. This strategy was not implemented in program.14.4 It did not produce errors. The reason is reading a string is coded differently from reading integers or floats. When we read a string which is at the end of the file, function end of file flag is marked (unlike) integer. We will say that the program worked correctly because we were lucky. Consider a case of counting the lines read in that program. We would have get value 0 when the file is empty. However, you will get wrong value of one. Therefore, we will recommend the strategy discussed earlier even when we are reading strings.
Read now
Unlock full access