I'm a newbie and I created a simple program, but I have one problem I can't deal with. I should work on Win CE.
Ok: I want this program to read 'array of arrays' and save encoded data into file.txt. Every 3 bytes from there should be encoded from ASCII (function below).
The biggest problem is with loop (or some other way to fix it) to read all array (without any skips).
Now it's like:
"qwer", "asdf" and it saves:
1 qwe
2 asd
/ the end of every line/array is lost /
it should be:
1 qwe
2 ras
3 df
I need it to be very simple - when the first array is done and some bytes are left, they are used to complete another 3-byte data with characters from the next array.
I would be very grateful for your help. I was looking it everywhere but I cannot find suitable answer.
Expand|Select|Wrap|Line Numbers
- #include <windows.h>
- #include <tchar.h>
- #include <stdio.h>
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- int encode(const char code[], int byte);
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
- {
- int j, y, n;
- int odl;
- int k=0;
- int w=1;
- char data [4][66]={
- "00i00i00i00i00k00k00n01101101101101101101100o00m00o00o0130130140",
- "1401201201401501701701701601701701601601501501501401401401401501",
- "501801<01<01?01D01D01D01F01F01L01O01R01T01V01W01X01X01X01Z01Z01Z",
- "01\01b01j02;02`09H09H09Z09Z09_0:90:90:@0:@0:@0:;0:@0:;0:;0:90:90",
- };
- ofstream myFile;
- myFile.open ("file.txt");
- for (j=0; j<3; ++j)
- {
- for (k=0; k<63; k=k+3)
- {
- odl = encode(&data[j][k], 3);
- myFile << w;
- myFile << " ";
- myFile << odl;
- myFile << endl;
- w++;
- }
- }
- myFile.close();
- return 3;
- }
- int encode(const char tab[], int byte)
- {
- int value = 0;
- int i;
- for (i = 0; i < byte; ++i)
- {
- value <<= 6;
- value &= ~0x3f;
- value |= tab[i] - 0x30;
- }
- return value;
- }