nfcdrummer
asked on
I need help with file access
Well...
I have a huge problem which is slowing the production of my program RIGHT down. It is a huge pain.
You cannot save or load a character properly. Or should I say, at all.
Since I am self-taught, I really don't know any good methods to do basically anything and am learning straight from the book. I would really like someone to totally re-write my code for the functions I use, or tell me exactly what to do. The most efficient way of this working, will get the points.
I'll post a few examples here:
void charstuff::WriteFileChar(c har givenname[50]) {
if ((PlayerFile = fopen(PlayFile, "rt")) == NULL) {
PlayerFile = fopen(PlayFile, "wt");
fclose(PlayerFile);
PlayerFile = fopen(PlayFile, "rt");
goto continuefile;
}
// CodeIt(PlayFile);
while (!feof(PlayerFile)) {
fscanf(PlayerFile,"%s\n",y ourname.c_ str());
if (yourname != NULL) numchars++;
if (yourname.c_str()
== givenname) { // These are used to see if the
CharError -> ShowModal();// Character already exists. If it does,
fileflag = 0;
goto stopreading; } // it returns an error window and stops
// searching through the char file.
for (tempint = 1 ; tempint < 180 ; tempint++)
fscanf(PlayerFile,tempstri ng);
checkint++;
if (checkint==200) {
CharError2 -> ShowModal();
fileflag = 2;
goto stopreading; }
}
continuefile:
fclose(PlayerFile);
PlayerFile = fopen(PlayFile, "at");
fputs(yourname.c_str(),Pla yerFile);
fputs(yourpassword.c_str() ,PlayerFil e);
fputs(IntToStr(yourstr).c_ str(),Play erFile);
fputs(IntToStr(yourint).c_ str(),Play erFile);
stopreading:
fclose(PlayerFile);
// CodeIt(PlayFile);
}
void charstuff::ReadFileChar(ch ar givenname[50]) {
// CodeIt(PlayFile);
PlayerFile = fopen(PlayFile, "rt");
while (!feof(PlayerFile)) {
fgets(yourname.c_str(),50, PlayerFile );
if (yourname == givenname) goto readitall; // These are used to see if the
}
readitall:
fgets(yourpassword.c_str() ,50,Player File);
ReadStats();
// CodeIt;
fclose(PlayerFile);
}
void charstuff::ListChars(void) {
// CodeIt(PlayFile);
PlayerFile = fopen(PlayFile, "rt");
CharCount = -1;
LoadCharForm->CharListBox- >Clear();
while (!feof(PlayerFile)) {
fgets(yourname.c_str(),50, PlayerFile );
fgets(yourpassword.c_str() ,50,Player File);
ReadStats();
CharCount++;
LoadCharForm->CharListBox- >Items->Ad d(yourname );
LoadCharForm->CharListBox- >Items->St rings[Char Count]
= yourname;
}
fclose(PlayerFile);
// CodeIt;
//LoadCharForm->CharListBo x->Items.S trings = ("");
}
void charstuff::ReadStats(void) {
fgets(IntToStr(yourstr).c_ str(),50,P layerFile) ;
fgets(IntToStr(yourint).c_ str(),50,P layerFile) ;
fgets(IntToStr(yourwis).c_ str(),50,P layerFile) ;
fgets(IntToStr(yourdex).c_ str(),50,P layerFile) ;
fgets(IntToStr(yourcon).c_ str(),50,P layerFile) ;
fgets(IntToStr(yourcha).c_ str(),50,P layerFile) ;
fgets(IntToStr(yourrace).c _str(),50, PlayerFile );
fgets(IntToStr(youralign). c_str(),50 ,PlayerFil e);
fgets(IntToStr(yourkills). c_str(),50 ,PlayerFil e);
fgets(IntToStr(yourcharm). c_str(),50 ,PlayerFil e);
fgets(IntToStr(yourlevel). c_str(),50 ,PlayerFil e);
fgets(IntToStr(youratt).c_ str(),50,P layerFile) ;
fgets(IntToStr(yourdef).c_ str(),50,P layerFile) ;
fgets(IntToStr(yourmagic). c_str(),50 ,PlayerFil e);
fgets(IntToStr(yourcash).c _str(),50, PlayerFile );
fgets(IntToStr(yourguild). c_str(),50 ,PlayerFil e);
fgets(IntToStr(yoursize).c _str(),50, PlayerFile );
fgets(IntToStr(yourhp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(yourmhp).c_ str(),50,P layerFile) ;
fgets(IntToStr(yoursp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(yourmsp).c_ str(),50,P layerFile) ;
fgets(IntToStr(yourexp).c_ str(),50,P layerFile) ;
fgets(IntToStr(yournexp).c _str(),50, PlayerFile );
fgets(IntToStr(stuexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(warexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(palexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(kniexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(sorexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(wizexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(magexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(thiexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(scaexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(heaexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(scoexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(seeexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(ninexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(vilexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(pyrexp).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(sturun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(warrun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(palrun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(knirun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(sorrun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(wizrun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(magrun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(thirun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(scarun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(hearun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(scorun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(seerun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(ninrun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(vilrun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(pyrrun).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(stulevel).c _str(),50, PlayerFile );
fgets(IntToStr(warlevel).c _str(),50, PlayerFile );
fgets(IntToStr(pallevel).c _str(),50, PlayerFile );
fgets(IntToStr(knilevel).c _str(),50, PlayerFile );
fgets(IntToStr(sorlevel).c _str(),50, PlayerFile );
fgets(IntToStr(wizlevel).c _str(),50, PlayerFile );
fgets(IntToStr(maglevel).c _str(),50, PlayerFile );
fgets(IntToStr(thilevel).c _str(),50, PlayerFile );
fgets(IntToStr(scalevel).c _str(),50, PlayerFile );
fgets(IntToStr(healevel).c _str(),50, PlayerFile );
fgets(IntToStr(scolevel).c _str(),50, PlayerFile );
fgets(IntToStr(seelevel).c _str(),50, PlayerFile );
fgets(IntToStr(ninlevel).c _str(),50, PlayerFile );
fgets(IntToStr(villevel).c _str(),50, PlayerFile );
fgets(IntToStr(pyrlevel).c _str(),50, PlayerFile );
fgets(friend1,50,PlayerFil e);
fgets(friend2,50,PlayerFil e);
fgets(friend3,50,PlayerFil e);
fgets(IntToStr(Companion1) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(Companion2) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(Companion3) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(Companion4) .c_str(),5 0,PlayerFi le);
// resistances
fgets(IntToStr(firres).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(colres).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(drares).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(poires).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(disres).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(parres).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(magres).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(minres).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(acires).c_s tr(),50,Pl ayerFile);
fgets(IntToStr(stores).c_s tr(),50,Pl ayerFile);
// put in items
fgets(IntToStr(itemslot1). c_str(),50 ,PlayerFil e);
fgets(IntToStr(itemslot2). c_str(),50 ,PlayerFil e);
fgets(IntToStr(itemslot3). c_str(),50 ,PlayerFil e);
fgets(IntToStr(itemslot4). c_str(),50 ,PlayerFil e);
fgets(IntToStr(itemslot5). c_str(),50 ,PlayerFil e);
fgets(IntToStr(itemslot6). c_str(),50 ,PlayerFil e);
fgets(IntToStr(itemslot7). c_str(),50 ,PlayerFil e);
fgets(IntToStr(itemslot8). c_str(),50 ,PlayerFil e);
fgets(IntToStr(itemslot9). c_str(),50 ,PlayerFil e);
fgets(IntToStr(itemslot10) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot11) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot12) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot13) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot14) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot15) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot16) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot17) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot18) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot19) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot20) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot21) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot22) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot23) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot24) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot25) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot26) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot27) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot28) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot29) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot30) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot31) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot32) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot33) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot34) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot35) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot36) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot37) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot38) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot39) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(itemslot40) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(eitemslot1) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(eitemslot2) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(eitemslot3) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(eitemslot4) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(eitemslot5) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(eitemslot6) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(eitemslot7) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(eitemslot8) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(eitemslot9) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(eitemslot10 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot11 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot12 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot13 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot14 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot15 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot16 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot17 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot18 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot19 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot20 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot21 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot22 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot23 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot24 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot25 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot26 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot27 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot28 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot29 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot30 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot31 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot32 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot33 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot34 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot35 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot36 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot37 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot38 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot39 ).c_str(), 50,PlayerF ile);
fgets(IntToStr(eitemslot40 ).c_str(), 50,PlayerF ile);
// Mine/Forest/Fortress positions.
fgets(IntToStr(MineX).c_st r(),50,Pla yerFile);
fgets(IntToStr(MineY).c_st r(),50,Pla yerFile);
fgets(IntToStr(MineZ).c_st r(),50,Pla yerFile);
fgets(IntToStr(ForestX).c_ str(),50,P layerFile) ;
fgets(IntToStr(ForestY).c_ str(),50,P layerFile) ;
fgets(IntToStr(FortressX). c_str(),50 ,PlayerFil e);
fgets(IntToStr(FortressY). c_str(),50 ,PlayerFil e);
fgets(IntToStr(FortressZ). c_str(),50 ,PlayerFil e);
fgets(IntToStr(CashInBank) .c_str(),5 0,PlayerFi le);
fgets(IntToStr(gold).c_str (),50,Play erFile);
fgets(IntToStr(gems).c_str (),50,Play erFile);
fgets(IntToStr(crystals).c _str(),50, PlayerFile );
}
I have a huge problem which is slowing the production of my program RIGHT down. It is a huge pain.
You cannot save or load a character properly. Or should I say, at all.
Since I am self-taught, I really don't know any good methods to do basically anything and am learning straight from the book. I would really like someone to totally re-write my code for the functions I use, or tell me exactly what to do. The most efficient way of this working, will get the points.
I'll post a few examples here:
void charstuff::WriteFileChar(c
if ((PlayerFile = fopen(PlayFile, "rt")) == NULL) {
PlayerFile = fopen(PlayFile, "wt");
fclose(PlayerFile);
PlayerFile = fopen(PlayFile, "rt");
goto continuefile;
}
// CodeIt(PlayFile);
while (!feof(PlayerFile)) {
fscanf(PlayerFile,"%s\n",y
if (yourname != NULL) numchars++;
if (yourname.c_str()
== givenname) { // These are used to see if the
CharError -> ShowModal();// Character already exists. If it does,
fileflag = 0;
goto stopreading; } // it returns an error window and stops
// searching through the char file.
for (tempint = 1 ; tempint < 180 ; tempint++)
fscanf(PlayerFile,tempstri
checkint++;
if (checkint==200) {
CharError2 -> ShowModal();
fileflag = 2;
goto stopreading; }
}
continuefile:
fclose(PlayerFile);
PlayerFile = fopen(PlayFile, "at");
fputs(yourname.c_str(),Pla
fputs(yourpassword.c_str()
fputs(IntToStr(yourstr).c_
fputs(IntToStr(yourint).c_
stopreading:
fclose(PlayerFile);
// CodeIt(PlayFile);
}
void charstuff::ReadFileChar(ch
// CodeIt(PlayFile);
PlayerFile = fopen(PlayFile, "rt");
while (!feof(PlayerFile)) {
fgets(yourname.c_str(),50,
if (yourname == givenname) goto readitall; // These are used to see if the
}
readitall:
fgets(yourpassword.c_str()
ReadStats();
// CodeIt;
fclose(PlayerFile);
}
void charstuff::ListChars(void)
// CodeIt(PlayFile);
PlayerFile = fopen(PlayFile, "rt");
CharCount = -1;
LoadCharForm->CharListBox-
while (!feof(PlayerFile)) {
fgets(yourname.c_str(),50,
fgets(yourpassword.c_str()
ReadStats();
CharCount++;
LoadCharForm->CharListBox-
LoadCharForm->CharListBox-
= yourname;
}
fclose(PlayerFile);
// CodeIt;
//LoadCharForm->CharListBo
}
void charstuff::ReadStats(void)
fgets(IntToStr(yourstr).c_
fgets(IntToStr(yourint).c_
fgets(IntToStr(yourwis).c_
fgets(IntToStr(yourdex).c_
fgets(IntToStr(yourcon).c_
fgets(IntToStr(yourcha).c_
fgets(IntToStr(yourrace).c
fgets(IntToStr(youralign).
fgets(IntToStr(yourkills).
fgets(IntToStr(yourcharm).
fgets(IntToStr(yourlevel).
fgets(IntToStr(youratt).c_
fgets(IntToStr(yourdef).c_
fgets(IntToStr(yourmagic).
fgets(IntToStr(yourcash).c
fgets(IntToStr(yourguild).
fgets(IntToStr(yoursize).c
fgets(IntToStr(yourhp).c_s
fgets(IntToStr(yourmhp).c_
fgets(IntToStr(yoursp).c_s
fgets(IntToStr(yourmsp).c_
fgets(IntToStr(yourexp).c_
fgets(IntToStr(yournexp).c
fgets(IntToStr(stuexp).c_s
fgets(IntToStr(warexp).c_s
fgets(IntToStr(palexp).c_s
fgets(IntToStr(kniexp).c_s
fgets(IntToStr(sorexp).c_s
fgets(IntToStr(wizexp).c_s
fgets(IntToStr(magexp).c_s
fgets(IntToStr(thiexp).c_s
fgets(IntToStr(scaexp).c_s
fgets(IntToStr(heaexp).c_s
fgets(IntToStr(scoexp).c_s
fgets(IntToStr(seeexp).c_s
fgets(IntToStr(ninexp).c_s
fgets(IntToStr(vilexp).c_s
fgets(IntToStr(pyrexp).c_s
fgets(IntToStr(sturun).c_s
fgets(IntToStr(warrun).c_s
fgets(IntToStr(palrun).c_s
fgets(IntToStr(knirun).c_s
fgets(IntToStr(sorrun).c_s
fgets(IntToStr(wizrun).c_s
fgets(IntToStr(magrun).c_s
fgets(IntToStr(thirun).c_s
fgets(IntToStr(scarun).c_s
fgets(IntToStr(hearun).c_s
fgets(IntToStr(scorun).c_s
fgets(IntToStr(seerun).c_s
fgets(IntToStr(ninrun).c_s
fgets(IntToStr(vilrun).c_s
fgets(IntToStr(pyrrun).c_s
fgets(IntToStr(stulevel).c
fgets(IntToStr(warlevel).c
fgets(IntToStr(pallevel).c
fgets(IntToStr(knilevel).c
fgets(IntToStr(sorlevel).c
fgets(IntToStr(wizlevel).c
fgets(IntToStr(maglevel).c
fgets(IntToStr(thilevel).c
fgets(IntToStr(scalevel).c
fgets(IntToStr(healevel).c
fgets(IntToStr(scolevel).c
fgets(IntToStr(seelevel).c
fgets(IntToStr(ninlevel).c
fgets(IntToStr(villevel).c
fgets(IntToStr(pyrlevel).c
fgets(friend1,50,PlayerFil
fgets(friend2,50,PlayerFil
fgets(friend3,50,PlayerFil
fgets(IntToStr(Companion1)
fgets(IntToStr(Companion2)
fgets(IntToStr(Companion3)
fgets(IntToStr(Companion4)
// resistances
fgets(IntToStr(firres).c_s
fgets(IntToStr(colres).c_s
fgets(IntToStr(drares).c_s
fgets(IntToStr(poires).c_s
fgets(IntToStr(disres).c_s
fgets(IntToStr(parres).c_s
fgets(IntToStr(magres).c_s
fgets(IntToStr(minres).c_s
fgets(IntToStr(acires).c_s
fgets(IntToStr(stores).c_s
// put in items
fgets(IntToStr(itemslot1).
fgets(IntToStr(itemslot2).
fgets(IntToStr(itemslot3).
fgets(IntToStr(itemslot4).
fgets(IntToStr(itemslot5).
fgets(IntToStr(itemslot6).
fgets(IntToStr(itemslot7).
fgets(IntToStr(itemslot8).
fgets(IntToStr(itemslot9).
fgets(IntToStr(itemslot10)
fgets(IntToStr(itemslot11)
fgets(IntToStr(itemslot12)
fgets(IntToStr(itemslot13)
fgets(IntToStr(itemslot14)
fgets(IntToStr(itemslot15)
fgets(IntToStr(itemslot16)
fgets(IntToStr(itemslot17)
fgets(IntToStr(itemslot18)
fgets(IntToStr(itemslot19)
fgets(IntToStr(itemslot20)
fgets(IntToStr(itemslot21)
fgets(IntToStr(itemslot22)
fgets(IntToStr(itemslot23)
fgets(IntToStr(itemslot24)
fgets(IntToStr(itemslot25)
fgets(IntToStr(itemslot26)
fgets(IntToStr(itemslot27)
fgets(IntToStr(itemslot28)
fgets(IntToStr(itemslot29)
fgets(IntToStr(itemslot30)
fgets(IntToStr(itemslot31)
fgets(IntToStr(itemslot32)
fgets(IntToStr(itemslot33)
fgets(IntToStr(itemslot34)
fgets(IntToStr(itemslot35)
fgets(IntToStr(itemslot36)
fgets(IntToStr(itemslot37)
fgets(IntToStr(itemslot38)
fgets(IntToStr(itemslot39)
fgets(IntToStr(itemslot40)
fgets(IntToStr(eitemslot1)
fgets(IntToStr(eitemslot2)
fgets(IntToStr(eitemslot3)
fgets(IntToStr(eitemslot4)
fgets(IntToStr(eitemslot5)
fgets(IntToStr(eitemslot6)
fgets(IntToStr(eitemslot7)
fgets(IntToStr(eitemslot8)
fgets(IntToStr(eitemslot9)
fgets(IntToStr(eitemslot10
fgets(IntToStr(eitemslot11
fgets(IntToStr(eitemslot12
fgets(IntToStr(eitemslot13
fgets(IntToStr(eitemslot14
fgets(IntToStr(eitemslot15
fgets(IntToStr(eitemslot16
fgets(IntToStr(eitemslot17
fgets(IntToStr(eitemslot18
fgets(IntToStr(eitemslot19
fgets(IntToStr(eitemslot20
fgets(IntToStr(eitemslot21
fgets(IntToStr(eitemslot22
fgets(IntToStr(eitemslot23
fgets(IntToStr(eitemslot24
fgets(IntToStr(eitemslot25
fgets(IntToStr(eitemslot26
fgets(IntToStr(eitemslot27
fgets(IntToStr(eitemslot28
fgets(IntToStr(eitemslot29
fgets(IntToStr(eitemslot30
fgets(IntToStr(eitemslot31
fgets(IntToStr(eitemslot32
fgets(IntToStr(eitemslot33
fgets(IntToStr(eitemslot34
fgets(IntToStr(eitemslot35
fgets(IntToStr(eitemslot36
fgets(IntToStr(eitemslot37
fgets(IntToStr(eitemslot38
fgets(IntToStr(eitemslot39
fgets(IntToStr(eitemslot40
// Mine/Forest/Fortress positions.
fgets(IntToStr(MineX).c_st
fgets(IntToStr(MineY).c_st
fgets(IntToStr(MineZ).c_st
fgets(IntToStr(ForestX).c_
fgets(IntToStr(ForestY).c_
fgets(IntToStr(FortressX).
fgets(IntToStr(FortressY).
fgets(IntToStr(FortressZ).
fgets(IntToStr(CashInBank)
fgets(IntToStr(gold).c_str
fgets(IntToStr(gems).c_str
fgets(IntToStr(crystals).c
}
You can not use strings c_str() function to _change_ the string, only to read it. You compiler should give an error message, something like, 'cannot convert const char* to char*'
You would likely need some char buffer[1000], read into that and assign it to the string:
char buffer[1000];
fgets(buffer, 50, PlayerFile);
itemslot11 = string(buffer);
It should be ok to use the c_str() member for writing to the file.
There could be more problems, but the wrong usage of string::c_str() was catching the eye.
You would likely need some char buffer[1000], read into that and assign it to the string:
char buffer[1000];
fgets(buffer, 50, PlayerFile);
itemslot11 = string(buffer);
It should be ok to use the c_str() member for writing to the file.
There could be more problems, but the wrong usage of string::c_str() was catching the eye.
ASKER
I'm sorrybut that doesn't answer ALL of my questions... Iknew it was wrong right from the start, but I needed to know how to do what I want to do PROPERLY before I look at fixing it... At the moment all I want to do is get it to work efficiently and properly
Basically I want to store a maximum of 200 chars details into 1 file, about 150 details for each char I would say. All of the details so far for each character are on the 'charstuff::readstats();" functon.
Basically I want to store a maximum of 200 chars details into 1 file, about 150 details for each char I would say. All of the details so far for each character are on the 'charstuff::readstats();" functon.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ohhhh I think I get you now.... I'll test it out...
but one thing, when it saves the datait doesn't save each seperate part on a seperate line... how can I put an end-of-line indicator on each thing...
would that be for instance:
oh and by the way... all of those variables are actally integers... not strings or chars...
so that would be like this:
char buffer[1000];
strcpy(buffer,(char)itemsl ot11+"\n") ;
fputs(buffer,PlayerFile);
fgets(buffer,1000,PlayerFi le)
itemslot11 = (int)buffer;
am I right?
but one thing, when it saves the datait doesn't save each seperate part on a seperate line... how can I put an end-of-line indicator on each thing...
would that be for instance:
oh and by the way... all of those variables are actally integers... not strings or chars...
so that would be like this:
char buffer[1000];
strcpy(buffer,(char)itemsl
fputs(buffer,PlayerFile);
fgets(buffer,1000,PlayerFi
itemslot11 = (int)buffer;
am I right?
ASKER
hey hangon a sec.... I just found out some REAL infomation on file streams... I'll try them like I originally intended to, then I'll see what works best
thanks for your help though
thanks for your help though
ASKER
hey well you're right... I'm giving you the points to be fair... I'm too tired to think straitght, but you gave me a better idea of how to write it properly...
now I'm using filestreams insted of FILE*...
thanks heaps
now I'm using filestreams insted of FILE*...
thanks heaps
>> strcpy(buffer,(char)itemsl ot11+"\n") ;
that cast (char)itemslot11 looks vey suspicious. What type is itemslot??
Indeed C++ iostreams are a better solution. I proposed the buffer idea just because it appeared to involve less modification work for you. I might have overlooked that iostreams are both easier to handle then FILE* i/o as well as safer in their type checking.
If you have any more questions, let me know.
that cast (char)itemslot11 looks vey suspicious. What type is itemslot??
Indeed C++ iostreams are a better solution. I proposed the buffer idea just because it appeared to involve less modification work for you. I might have overlooked that iostreams are both easier to handle then FILE* i/o as well as safer in their type checking.
If you have any more questions, let me know.
ASKER
itemslot1 through to 40 are all signed integers. Some others are unsigned long integers, but I'm having trouble using those with the StrToInt/IntToStr commands.
If you could help me with that type I'd appreciate it.
If you could help me with that type I'd appreciate it.
The cast is completely out of place. So lets get on. Do you want to use FILE* file i/o or C++ file streams?
ASKER
Well I've finished changing it all over to file streams... It works fine except that it still doesn't add the newline characters...
and when you go to load a character it still doesn't show the name or anything I'll emailyou the entire code ok??
Please see if you can fix it up... I think thats worth 150 points
and when you go to load a character it still doesn't show the name or anything I'll emailyou the entire code ok??
Please see if you can fix it up... I think thats worth 150 points
Ok, my mail address is also in my profile (many experts do so): mailto:kangaroo@xs4all.nl
Mh, too bad, EE shoes http hyperlinks links but not e-mail addresses :(
ASKER