File IO-2

File IO-2 - FileI/OPartII Sentinel logic again...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
File I/O Part II Sentinel logic again!
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Processing a file's data you must know how the data is arranged in the file, or you can't read it different ways to process all the data in the file one is put a count in the beginning that tells you how many pieces there are the other is to put in some indicator - a sentinel - at the end of the data
Background image of page 2
Counter controlled reading infile >> howmany; ct = 0; while (ct < howmany) { infile >> data; // process data ct ++; } // don't forget to put the count in the file! And // make sure it's right!!
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sentinel controlled reading more flexible - can add or take away data in file without having to change count either use literal sentinel number OR use the file stream state itself as the event to end the loop
Background image of page 4
Literal Sentinel value infile >> data; // priming read, remember? while (data != sentinel value) { // process data infile >> data; } // don't forget to put the sentinel value in // there!!
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/13/2011 for the course CS 115 taught by Professor Staff during the Fall '08 term at Kentucky.

Page1 / 11

File IO-2 - FileI/OPartII Sentinel logic again...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online