Question: Write a function to read a binary file in random access mode. Your function will open a file that contains a list of 4-byte binary

Write a function to read a binary file in "random access" mode. Your function will open a file that contains a list of 4-byte binary integers. You should read the first integer to find the index of the next integer, print this index to an ostream, and repeat until you hit a negative integer. *IF* the file was an array of integers, you'd be doing something like this:

int i=0;

while (i >=0 ){

i = myArray[i];

cout << i << " ";

}

You can implement this using either seekg to jump around in the file or by reading the whole file into a big array first.

Your function should be called numberChase and should take two parameters, a C++ string for the filename, and an ostream to print the indices too.

(HINT: The first file that the instructors testing program checks contains the four integers +3 0 -77 +2; you're supposed to follow the integers. So after reading the 3, you jump to *integer* 3; this has the value 2, so you jump to *integer* 2; this has the value -77 so you stop.)

(You only write the function, and the instructor's given test program tests it with given binary files.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!