126k views
4 votes
If a random access file contains a stream of characters, which of the following would you use to set the pointer on the fifth character?

a.file.seek (10);
b.ile.seek (5);
c.file.seek (4) ;
d.file.seek (8) ;

User Indrek Ots
by
8.3k points

1 Answer

0 votes

Final answer:

To set the pointer to the fifth character in a character stream using a random access file, you would use the command file.seek(4) because indexing starts at zero.

Therefore, the correct answer is: option c. file.seek (4)

Step-by-step explanation:

If a random access file contains a stream of characters and you want to set the pointer on the fifth character, you would typically use the file pointer method seek with a parameter that specifies the number of bytes to move the file pointer from the beginning of the file.

An application can position the file pointer to a specified offset by calling SetFilePointer. The SetFilePointer function can also be used to query the current file pointer position by specifying a move method of FILE_CURRENT and a distance of zero.

Character streams are usually indexed starting at zero, so the first character is at position 0. Therefore, to set the pointer to the fifth character, you would move to the fourth position. The correct command from the given options would be file.seek(4).

User Newt
by
8.4k points