Hello,
I want to copy every 4th byte of file_1.bin into file_2.bin
For example - if the contents of file_1.bin are :
0x0 // Byte 1
0x1 // Byte 2
0x2 // Byte 3
0xAB // Byte 4 Skip when copying.
0x3 // Byte 1
0x4 // Byte 2
0x5 // Byte 3
0xAA // Byte 4 Skip when copying.
0x6 // Byte 1
0x7 // Byte 2
0x8 // Byte 3
0xFF // Byte 4 Skip when copying.
0x9 // Byte 1
0xA // Byte 2
0xB // Byte 3
0x1 // Byte 4 Skip when copying.
0xC // Byte 1
the contents of file_2.bin will be :
0x0
0x1
0x2
0x3
0x4
0x5
0x6
0x7
0x8
0x9
0xA
0xB
0xC
file_1.bin can be any size.
This is the C++ program that I wrote - but it doesn't work.
Please help me fix it :
Code:
#include <iostream>
#include <fstream>
using namespace std ;
int main ( )
{
ifstream file_1 ( "file_1.bin", ios::out | ios::app | ios::binary ) ;
ofstream file_2 ( "file_2.bin", ios::out | ios::app | ios::binary ) ;
int index ;
char ch ;
for ( index = 1 ; file_1.eof ( ) != 1 ; index ++ )
{
if ( index % 4 )
{
file_1.get(ch) ;
file_2 << ch ;
}
}
return 0 ;
}