[RESOLVED] Problems reading integers and strings from txt file ...
sorry for being thick ... but im trying to save data to a text file and need to store my integers as char values how do i do this
regards
john
Re: char[] to int ? c++ and int to char[]
i dont understand ... this is the problem im having ....
im storing a text string that says 'Duolc'
and when i read it its being returned as 'Doud' ??
even when i debug and step through my code the value says its 'Duolc' but when its printed to the screen it outputs 'Doud' ???
any ideas ?
Re: char[] to int ? c++ and int to char[]
and my first post refers to problems im having reading integers from and the second text strings ....
Quote:
CNAME
Duolc
CATTACK
100
CDEFENCE
0
CPSTRENGTH
0
CMSTRENGTH
0
CHP
100
CMP
100
^^ there's the file structure
all i want todo is read cname into a char variable and the rest of the vars to integers
^^ maybe that'll be of further use ;)
Re: Problems reading integers and strings from txt file ...
When you write and read your file, use b. My wife if kicking me off off, gotta go.
Re: Problems reading integers and strings from txt file ...
.... ???
please get back to me mate im still really stuck
Re: Problems reading integers and strings from txt file ...
ahhh do you mean read by byte ?
Re: Problems reading integers and strings from txt file ...
... nope still cant figure it out ??
Re: Problems reading integers and strings from txt file ...
Please post your code. Just supposing doesnt help here.
Re: Problems reading integers and strings from txt file ...
VB Code:
int OpenCharacter (char *FileName) {
//ResetCharacterVars();
char myline[]=""; //
char fname[256]="";
int iReturn=0;
//strcat(fname, szDirectory);
strcat(fname, "Characters/");
strcat(fname, FileName);
strcat(fname, ".chr");
ifstream myfile (fname);
if (myfile.is_open())
{
bool FinishedReading=FALSE;
while (!myfile.eof() )
{
char myLine[100];
int intVal=0;
//string line; //[256]="";
if (!FinishedReading){
myfile >> myLine; // skip CNAME identifier
myfile >> myLine; // read real cname
strcpy(CSNAME, myLine); // copy to string
myfile >> myLine; // Attack points marker
myfile >> CSATTACK; // read real value
myfile >> myLine; // defence points marker
myfile >> CSDEFENCE; // read real value
myfile >> myLine; // Strength points marker
myfile >> CSPSTRENGTH; // read real value
myfile >> myLine; // Magic points marker
myfile >> CSMSTRENGTH; // read real value
myfile >> myLine; // init hp points marker
myfile >> intVal; // read real value
myfile >> myLine; // init hp points marker
myfile >> intVal; // read real value
FinishedReading=TRUE;
}
myfile >> myLine;
}
myfile.close();
iReturn=1;
}
else {
//cout << "Unable to open character file";
//getch();
iReturn=0;
}
return iReturn;
}
Re: Problems reading integers and strings from txt file ...
its cool i got it working .... lol ...
defined a 'character' structure in another file and it now seems to be reading writing to the structure and to the screen fine
thanks for your time any way ;)