Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actuale‍dd

Posted 31 December 2012 - 01:26 PM

Suppose I have a file like this:
1
2
3
4
Are you saying it contains the bytes 0x30, 0x0D, 0x0A, 0x31, 0x0D, 0x0A, 0x32, 0x0D, 0x0A, 0x33 (assuming little endian and typical windows text formatting)?
Or are you saying it contains something like 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00?

The distinction is important. But I'll assume the latter as that's what the rest of your question implies.


and I can use fread [...3 times...]

exactly like that,will mFile contain:
1
2
3
Reading a file does not change its content. Think of a FILE as containing a pointer or cursor in it somewhere that is moved along every time you read something from the file.

The first fread() call will read an int (on success) and advance the cursor sizeof(int) bytes, so that the cursor is now at 0x02,00,00,00 (again assuming 'binary' formatting).

The fseek() function allows you to change the position of this cursor. ftell() tells you its position.

Not sure if this answers your question directly, but I hope it helps.

EDIT: ninja'd :(

#3e‍dd

Posted 31 December 2012 - 01:24 PM

Suppose I have a file like this:
1
2
3
4
Are you saying it contains the bytes 0x30, 0x0D, 0x0A, 0x31, 0x0D, 0x0A, 0x32, 0x0D, 0x0A, 0x33 (assuming little endian and typical windows text formatting)?
Or are you saying it contains something like 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00?

The distinction is important. But I'll assume the latter as that's what the rest of your question implies.


and I can use fread [...3 times...]

exactly like that,will mFile contain:
1
2
3
Reading a file does not change its content. Think of a FILE as containing a pointer or cursor in it somewhere that is moved along every time you read something from the file.

The first fread() call will read an int (on success) and advance the cursor sizeof(int) bytes, so that the cursor is now at 0x02000000 (again assuming 'binary' formatting).

The fseek() function allows you to change the position of this cursor. ftell() tells you its position.

Not sure if this answers your question directly, but I hope it helps.

EDIT: ninja'd :(

#2e‍dd

Posted 31 December 2012 - 01:22 PM

Suppose I have a file like this:
1
2
3
4
Are you saying it contains the bytes 0x30, 0x0D, 0x0A, 0x31, 0x0D, 0x0A, 0x32, 0x0D, 0x0A, 0x33 (assuming little endian and typical windows text formatting)?
Or are you saying it contains something like 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00?

The distinction is important. But I'll assume the latter as that's what the rest of your question implies.


and I can use fread [...3 times...]

exactly like that,will mFile contain:
1
2
3
Reading a file does not change its content. Think of a FILE as containing a pointer or cursor in it somewhere that is moved along every time you read something from the file.

The first fread() call will read an int (on success) and advance the cursor sizeof(int) bytes, so that the cursor is now at 0x02000000 (again assuming 'binary' formatting).

The fseek() function allows you to change the position of this cursor. ftell() tells you its position.

Not sure if this answers your question directly, but I hope it helps.

#1e‍dd

Posted 31 December 2012 - 01:21 PM

Suppose I have a file like this:
1
2
3
4

Are you saying it contains the bytes 0x30, 0x0D, 0x0A, 0x31, 0x0D, 0x0A, 0x32, 0x0D, 0x0A, 0x33 (assuming little endian and typical windows text formatting)?

Or are you saying it contains something like 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00?

 

The distinction is important. But I'll assume the latter as that's what the rest of your question implies.

 

 

 

and I can use fread [...3 times...]

exactly like that,will mFile contain:
1
2
3
 

 

Reading a file does not change its content. Think of a FILE as containing a pointer or cursor in it somewhere that is moved along every time you read something from the file.

 

The first fread() call will an int (on success) and advance the cursor sizeof(int) bytes, so that the cursor is now at 0x02000000 (again assuming 'binary' formatting).

 

The fseek() function allows you to change the position of this cursor. ftell() tells you its position.

 

Not sure if this answers your question directly, but I hope it helps.


PARTNERS