reading binary data with number of bytes

Started by
12 comments, last by bilstonwarrior 21 years, 2 months ago
right so, if i am reading in a binary file and want to flip all the bytes that are read in, and the bytes read are 4096... how do i flip all the bits...????

i have the following function:


void ReadFile( void *buffer)
{
fread(buffer,4096,1,infile);

// this doesnt work:
binary_flip(&buffer, sizeof(buffer));


}

if i use the "binary_flip" code from one of the answers above, it still doesnt fip everything.

What i need to do if flip all the bytes currently held in "buffer" once it is read in using 4096 bytes.

i have been told that by doing "*(unsigned int *)buffer = ~(*(unsigned int*)buffer);" this is only flipping 1 DWORD.... so how do i flip it all?

thanks

Paul.
Advertisement
binary_flip(buffer, 4096);


Update GameDev.net system time campaign: ''date ddmmHHMMYYYY''
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
great thanks, it works!!
Short explanation: Since buffer is a pointer (type void*), its size is that of a pointer (at least that''s how i understand it). So its size will be that of a pointer - 4 bytes on a 32 bit machine.

"George W. Bush Geography Simplification Initiative"

More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
---Just trying to be helpful.Sebastian Beschkehttp://randomz.heim.at/

This topic is closed to new replies.

Advertisement