?
Vielen Dank, hab das ganze jetzt komplett umgeschrieben und es funktioniert jetzt.
Sieht so aus:
[code]
void Highscore::split(string source, const char* delimeter, string array[])
{
int j = 0, k = -1;
unsigned int i = 0;
string str;
i = source.find(delimeter, i + 1);
while(i != string::npos)
{
array[j] = str.assign(source, k + 1, i - (k + 1));
j++;
k = i;
i = source.find(delimeter, i + 1);
}
}
void Highscore::read()
{
char scorepfad[MAX_PATH];
GetCurrentDirectory(MAX_PATH, scorepfad);
ldatei.open(strcat (scorepfad, "\\highscore.hsc"), ios::binary);
ldatei.seekg(0, ios::end);
size_t len = ldatei.tellg();
ldatei.seekg(0, ios::beg);
char* buf = new char[len];
ldatei.read(buf, len);
ldatei.close();
string str = crypt(buf, "downtimes", false, len);
delete[] buf;
split(str, "~", &score[0]);
}
void Highscore::write(string name, int punkte)
{
char scorepfad[MAX_PATH];
GetCurrentDirectory(MAX_PATH, scorepfad);
string p;
ostringstream Str;
Str << punkte;
p = Str.str();
for(int i = 19; i > pos; i--)
{
score[i] = score[i - 2];
i--;
score[i] = score[i - 2];
}
score[pos * 2] = name;
score[pos * 2 + 1] = p;
string s;
for(int i = 0; i < 20; i++)
{
s += score[i];
s += "~";
}
char* buf = new char[s.size()];
strcpy(buf, s.c_str());
s = crypt(buf, "downtimes", true, s.size());
strcpy(buf, s.c_str());
sdatei.open(strcat (scorepfad, "\\highscore.hsc"), ios::binary | ios_base::trunc);
sdatei.write(buf, s.size());
sdatei.close();
delete[] buf;
};
string Highscore::crypt(char* inp, string key, bool mode, int len)
{
string z;
char c;
unsigned int position = 0;
int cptzahl, orgzahl, keyzahl;
for(int i = 0; i < len; i++)
{
strcpy(&c, key.substr(position, 1).c_str());
keyzahl = c;
position++;
if(position > key.length())
position = 0;
if(mode)
{
//Verschlüsseln
orgzahl = inp[i];
cptzahl = orgzahl ^ keyzahl;
z += cptzahl;
}
else
{
//Entschlüsseln
cptzahl = inp[i];
orgzahl = cptzahl ^ keyzahl;
z += orgzahl;
}
}
return z;
};
[/code]