I am supposed to use a for loop for use input
-Not sure why a for loop? I mean all this program does is keep on asking the user to input a filename, a starting seek adds and the # of bytes to read off.
For example, the input should look like:
%myprog
Enter filename:datafile
Start seek:0
Bytes to read:65
My block size in this program is 20, so the output would be:
“m/n/files/program/test/datafile” block 0 read – 20 bytes
01234567890123456789
“m/n/files/program/test/datafile” block 1 read – 20 bytes
01234567890123456789
“m/n/files/program/test/datafile” block 3 read – 20 bytes
01234567890123456789
“m/n/files/program/test/datafile” block 0 read – 5 bytes
01234
So I am not sure why/how I would use a for loop to ask for user input. All we are doing is keep on asking the user to enter different files and seek ranges. The assignment does not say where to stop asking.
The
forloop is the universal looping construct in C.The following loops are equivalent.
FOR LOOP
WHILE LOOP
Assuming you know this, you could write the following rather obtuse code, although it might be frowned upon: