Jump to content

fread and fseek don't advance buffer

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
RobotGymnast

RobotGymnast

    Programmer

  • Members
  • PipPipPipPip
  • 143 posts
Neither fread nor fseek in my code advance the cursor position the file, whether I opened it as r or r+, and I (obviously) require the cursor to change to read past the first few bytes.


FILE* values;

fopen_s(&values,"values.txt","rb");

char bytes_read[2][4];


for(int min=0;min<2;++min)

{

	// read the bytes for the maximum value of the hack

	fread(bytes_read[min],2,1,values);

	// advance the file

	fseek(values,2,SEEK_CUR);

}

the 2s in fseek and fread are actually from another variable, but I substituted here for readability.

This code doesn't work for me.

Any help?

Edit: Nevermind. The file I was attempting to read consisted of: 27 0F 00 01 27 0F 00 01 ... so when I read two bytes I got 27 0F.. then it advanced the buffer by 2.. however, the fseek advanced the buffer by an EXTRA 2, which brought me to the next 27 0F. sorry

Edited by RobotGymnast, 28 October 2008 - 02:36 PM.


#2
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts
Would error checking the return values of fopen_s, fread, and fseek tell you more?

#3
RobotGymnast

RobotGymnast

    Programmer

  • Members
  • PipPipPipPip
  • 143 posts
repetetive file + bad code. sorry