Unfortunately, I lost all my code, this is all I have managed to rebuild (as a short cut a friend suggested I try to make it more like a linked list):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
struct Data
{
int leftChildBlockNo; // 8 bytes
int rightChildBlockNo; // 8 bytes
int id[10]; // 8 bytes
char firstName[30]; // 30 bytes
char lastName[30]; // 30 bytes
char streetOne[30]; // 30 bytes
char streetTwo[30]; // 30 bytes
char city[30]; // 30 bytes
char state[20]; // 20 bytes
char zip[10]; // 10 bytes
char country[30]; // 30 bytes
char filler[22]; // 22 bytes
};
struct FileData
{
int rootBlockNo;
int lastBlockNoWritten;
};
struct Data *GetProfile() {
struct Data newProfile;
char instr[256];
cout << "Enter data: ";
cin >> instr;
if (strlen(instr) == 0) {// If profilestring is empty
return 0;
} else {
// Split the string...
newProfile.id = 3;
strcpy(newProfile.firstName,"Jon");
}
return &newProfile;
}
int main(void) {
struct Data rootNode;
struct Data *newProfile;
newProfile = GetProfile();
while (newProfile != NULL) {
newProfile = GetProfile();
}
}
|
plus this:
1. Choose a block size of 256 from ->
1. 7 times 30 = 210
2. 8 for the ID
3. 8 for the two children using block numbers
2. So we need a function that will get a block of 256 bytes using block number
3. Use block 0 as the root.
4. All numbers will be store as text using hexadecimals. So must have a function to convert from text to int and int to text.
5. Now we can make a struct that can contain the data and not worry about 32 bit verses 64 bit.
6. So
struct Data
{
int64_t leftChildBlockNo; // 8 bytes
int64_t rightChildBlockNo; // 8 bytes
int64_t id[10]; // 8 bytes
char firstName[30]; // 30 bytes
char lastName[30]; // 30 bytes
char streetOne[30]; // 30 bytes
char streetTwo[30]; // 30 bytes
char city[30]; // 30 bytes
char state[20]; // 20 bytes
char zip[10]; // 10 bytes
char country[30]; // 30 bytes
char filler[22]; // 22 bytes
};
7. You need to keep tract of the last block no that you have written. For this reason it might be better to reserve block 0 to store
8.struct FileData
{
int64_t rootBlockNo;
int64_t lastBlockNoWritten;
}
9. You will need to update the 0 block everytime you add a block so that lastBlockNoWritten is updated.