01-07-2013 07:20 AM
Hi,
Using the example at http://developer.blackberry.com/native/documentati
Im trying to save data in a file for my game. My code is as follows:
std::string path1 = CCFileUtils::sharedFileUtils()->getWriteablePath(); path1.append("save.dat"); FILE *fp = fopen(path1.c_str(), "wb"); CCLog("path is %s",path1.c_str()); if (!fp) { CCLog("error!!!!!"); } else { int page; int firstRead = fscanf(fp, "%i", &page); CCLog("file read value is %d %d",firstRead,page); if(firstRead == -1) { fprintf(fp,"%i",globalVolume); fprintf(fp,"%i",globalLevel); fprintf(fp,"%i",_timeAttack); fprintf(fp,"%i",_maxStreak); for(int i = 0;i < 30; i++) { fprintf(fp,"%i",((CCString *)_score->objectAtIndex(i))->intValue()); } } } // fprintf(fp, "%i", page); fclose(fp); fp = fopen(path1.c_str(), "wb"); if (!fp) { CCLog("error!!!!!"); } else { int page; int firstRead = fscanf(fp, "%i", &page); CCLog("file read value is %d %d",firstRead,page); } fclose(fp);
The ouput that I get is :
path is /accounts/1000/appdata/org.cocos2dx.Test.testDev__
cocos2d-x debug info file read value is -1 -1323428880
read value is -1 -1323428880
read value is -1 -1323428880.
I am testing this on the simulator. Is there anything wrong with what Im doing? Does file saving work on the simulator?
Thanks.
Solved! Go to Solution.
01-08-2013 01:53 AM
Just checked on the Device. Does not work there too. The output i get is :
cocos2d-x debug info path is /accounts/1000/appdata/org.cocos2dx.Test.testDev__Test2c5a53de/data/save.dat
cocos2d-x debug info file read value is -1 136197336
cocos2d-x debug info file read value is -1 136197336
01-08-2013 09:29 AM
01-08-2013 09:51 AM
01-08-2013 10:06 AM
01-08-2013 11:09 AM
01-08-2013 11:45 AM
01-08-2013 01:08 PM
Thanks! Using fwrite and fread did the trick for me!
01-08-2013 02:22 PM