Hi,
im trying to save player names and points to a file. It does not work like expected. Maybe there is a mistake in the code but i dont get it. Do you have an idea?
The char player1Name is defined in another function. For example "MAX"...
void saveName()
{
char szLine[1];
char* fstring;
if (dbFileExist("playerdata.txt"))
{
dbOpenToRead(1,"playerdata.txt");
while (!dbFileEnd( 1 ))
{
fstring = dbReadString(1, szLine);
}
dbCloseFile( 1 );
}
dbDeleteFile("playerdata.txt");
dbOpenToWrite(1,"playerdata.txt");
char writeString[1000000];
strcat(writeString,fstring);
strcat(writeString,"|");
strcat(writeString,player1Name);
strcat(writeString,"|0");
dbWriteString(1,writeString);
dbCloseFile( 1 );
}
The containment of a existing file could be:
"TOM|200|PETER|300"
After calling saveName() the containment should be
"TOM|200|PETER|300|MAX|0"
The result is:
" TOM|200|PETER|300|MAX|0" ( <-- char one is a space!)
after a secound try:
" |MAX|0"
instead of "TOM|200|PETER|300|MAX|0|MAX|0" ......
Appart from the problem it doesnt work... Is there a better way to code this? I would like to append the new text to the end of the file, but there isnt a db-function for this, is there?
I would try to write the code with fstream and iostream functions but i get an error. I cant include the librarys... Someone else had this problem before in this forum, but there was not really a solution.
Daniel