What NOT to do with File IO
· Read ALL patterned data in ONE pass in a loop
o used a while loop
o but read ALL data in ONE iteration of the loop, so didn’t use the loop
· printf or scanf
o YOUR NOT GETTING ANYTHING FOR THE KEYBOARD!!
o I am NOT to see a scanf UNLESS
§ getting the file FROM THE USER
o printf DOES NOT DISPLAY AN ENTIRE FILE
§ you need to read in the line from the file first and place into a string variable
§ then display THE VARIABLE
· Use a for loop to read the values inside the file.
o You might know how many values are there with the files I GIVE you
§ but what if you didn’t know how many where going to be there, but you knew the pattern?
|No No #3
|Using a for loop to read data
// how many values will this read?
for (int i = 0; i < 9; i++)
fscanf(infile, "%d", &num);
total += num;