The start pointer of array will change if you call read() function, because you want to read the file in a stream style instead of always starting over.
No, you don't have to take care of this.
The only thing is when you call read4() which reads 4 bytes into your buffer you might read more than you need, so you want to store those bytes in the structure, and next time you call read will start from those stored bytes, then read more from the file.
Think that you have 4 chars "a, b, c, d" in the file, and you want to call your function twice like this:
- read(buf, 1); // should return 'a'
- read(buf, 3); // should return 'b, c, d'
All the 4 chars will be consumed in the first call. So the tricky part of this question is how can you preserve the remaining 'b, c, d' to the second call.
@laonawuli What if we call read4 and use buf-- to get back to a?
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.