PeterVarain
asked on
Replace value in QByteArray & QDataStream
Hi experts,
I'm trying without success to replace some values in a byte array or in a data stream in QT 4.7
Here's my situation:
I have a binary file with data. Each two bytes of this file represent a signed integer value. I need to replace all the integer values which are 0 with 22 and save the file with the new values.
Any ideas how to proceed ?
Thanks,
Peter
I'm trying without success to replace some values in a byte array or in a data stream in QT 4.7
Here's my situation:
I have a binary file with data. Each two bytes of this file represent a signed integer value. I need to replace all the integer values which are 0 with 22 and save the file with the new values.
Any ideas how to proceed ?
Thanks,
Peter
Opps... that should have been something like
f.Write( &v22, 2 )
and you might have to type case the pointers to get something like this to properly compile.
f.Write( &v22, 2 )
and you might have to type case the pointers to get something like this to properly compile.
ASKER
Sorry, I haven't explained very clear what I want to do here...
The file which is saved is not the same file (the source file). I need to move all the data from the source file to a QByteArray and in the process change the 0 values to 22. Then, I need to compress this byte array with qCompress and only then write it to a newly created file.
So, my problem is that I have to move the data from the source file to the byte array and change to zeros...
All the best,
Peter
The file which is saved is not the same file (the source file). I need to move all the data from the source file to a QByteArray and in the process change the 0 values to 22. Then, I need to compress this byte array with qCompress and only then write it to a newly created file.
So, my problem is that I have to move the data from the source file to the byte array and change to zeros...
All the best,
Peter
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
there is a ) missing at right of while statement.
Sara
Sara
ASKER
Thanks Sara!
CFile f;
f.Open( strFileName, CFile::modeRead | CFile::modeWrite );
DWORD i;
const DWORD v22 = 22;
while( f.Read( &i, 2 ) == 2 )
{
if( i == 0 )
{
f.Seek( -2, CFile::current );
f.Write( &v22 );
}
}
If there is an issue with byte order, then you just need to replace v22=22 with v22=0x1600;