|
-
Apr 2nd, 2006, 04:37 PM
#1
Thread Starter
Lively Member
[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
Last edited by Hack; Apr 13th, 2006 at 12:23 PM.
Reason: Added [RESOLVED] to thread title and green "resolved" checkmark
-
Apr 2nd, 2006, 08:51 PM
#2
Thread Starter
Lively Member
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 ?
-
Apr 2nd, 2006, 08:53 PM
#3
Thread Starter
Lively Member
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 ....
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
-
Apr 3rd, 2006, 06:14 AM
#4
Frenzied Member
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.
-
Apr 3rd, 2006, 07:10 AM
#5
Thread Starter
Lively Member
Re: Problems reading integers and strings from txt file ...
.... ???
please get back to me mate im still really stuck
-
Apr 3rd, 2006, 07:11 AM
#6
Thread Starter
Lively Member
Re: Problems reading integers and strings from txt file ...
ahhh do you mean read by byte ?
-
Apr 3rd, 2006, 07:30 AM
#7
Thread Starter
Lively Member
Re: Problems reading integers and strings from txt file ...
... nope still cant figure it out ??
-
Apr 3rd, 2006, 07:37 AM
#8
Lively Member
Re: Problems reading integers and strings from txt file ...
Please post your code. Just supposing doesnt help here.
"bla, bla,... exists number M so for each n > M bla, bla..." Exists? Where is it? (Kronecker said...)
-
Apr 3rd, 2006, 08:04 AM
#9
Thread Starter
Lively Member
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;
}
-
Apr 3rd, 2006, 08:26 AM
#10
Thread Starter
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|