Hi. Sorry for not being specific. Im trying to do the second one. The one on swapping the low order bytes with the high order ones. Im using VC6.
-
#include <iostream>
-
#include <fstream>
-
using namespace std;
-
-
ifstream file;
-
ofstream newFile;
-
-
int main ()
-
{
-
int j = 0, i;
-
char array[10], chg[5];
-
-
file.open ("s0455_re.dat", ios::in|ios::binary);
-
newFile.open ("NewFile.bin", ios::out|ios::binary);
-
-
if (file.is_open())
-
{
-
cout << "Able to open file!" << endl;
-
-
if (newFile.is_open())
-
{
-
cout << "Able to open new file!" << endl;
-
-
while (j < 10) // loop while extraction from file is possible
-
{
-
array[j] = file.get(); // get character from file
-
j++;
-
}
-
-
j = 0;
-
-
for (i=0; i<5; i++) // i is half of j
-
{
-
chg[i] = ((int) array[j+1] << 8) + array[j]; // swap position
-
newFile << chg[i];
-
-
j = j + 2;
-
}
-
newFile.close();
-
}
-
-
else
-
cout << "Unable to open new file.";
-
-
file.close();
-
}
-
else
-
cout << "Unable to open file";
-
-
return 0;
-
}
In the swap position, Im trying to swap the position of the first byte with the second one, the third with the forth and so on. But when i write on the newFile, its only the first, third etc bytes are written. What should i do for the swap position?
Thanks for your patience.