Hey, Something really strange is happening and its really not a good time....
My File I/O was working perfect for the last 2 weeks, now, all of a sudden it is all jumped CRAP and doesnt work correctly. This is the function I use to load the data:
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
|
bool loadUserData()
{
FILE* fileHandle;
std::string tmp = "..//Data//Login//USERInfo.txt";
const char* str = tmp.c_str();
fileHandle = fopen(str,"r");
if(fileHandle==NULL)
{
return false;
}
std::string tmpname = "";
std::string tmppass = "";
const char* name = tmpname.c_str();
const char* pass = tmppass.c_str();
int health = -1;
int armour = -1;
int lives = -1;
while( true ) {
Player user;
int vals_read = fscanf(fileHandle,"%s %s %d:%d:%d",name,pass,&health,&armour,&lives);
if( vals_read == 5 ) {
// process the line
user.setName(name);
user.setPass(pass);
user.setHealth(health);
user.setArmour(armour);
user.setLives(lives);
table.Insert(user.getName(),user);
playerList.Append(user);
//best case is O(c) for insert depending on if a collision occurs or not
} else if( feof( fileHandle ) )
break;
}
fclose(fileHandle);
return true;
}
|
The file contains this: ANDY tests 100:30:4
I dont get any errors, it seems to work, but the values for name,pass,health,lives,armour are not correct.
for example, name as this weird value:
name = 0x77c2c2e3 "ÃÌÌÌÌÌjhˆ Áwè+±"
health = 1244424
etc...It was working perfectly fine until now...WTF