Stream->Readline help
by James Laker (BurNinG) · in Torque Game Engine · 03/10/2007 (5:25 am) · 2 replies
So here I am again with a problem I just cant get my head around. I'm getting strange results. I have a file with integers in them. The stream works fine, yada yada...
Here's the code:
The results:
buffer (string)= 2343
myCount= 128736786786837200000000.0000 (or something massive like that)
myCount= 0.0000
So what am I doing wrong here? Should the last myCount be 2342?
I've also tried:
myCount = (S32)buffer;
myCount = (U32)buffer;
So I dont understand and need YOUR help.
Here's the code:
char buffer[512];
U32 myCount;
stream->readLine((U8*)buffer,512);
if(stream->getStatus() == Stream::EOS) return false;
Con::printf("buffer (string)= %s",buffer);
//How many stars we have in the file
myCount= dAtof( buffer ); // <-- This aint working
Con::printf("myCount= %f",myCount);
starCount = dAtoi( buffer ); // <-- This aint working
Con::printf("myCount= %d",myCount);The results:
buffer (string)= 2343
myCount= 128736786786837200000000.0000 (or something massive like that)
myCount= 0.0000
So what am I doing wrong here? Should the last myCount be 2342?
I've also tried:
myCount = (S32)buffer;
myCount = (U32)buffer;
So I dont understand and need YOUR
#2
Thanx alot though
03/10/2007 (5:51 am)
Hehe... Just when I came to delete my post before I looked like an total idiot...Thanx alot though
Torque 3D Owner Tony Richards
Try using F32 intead of U32 / S32, or use dAtoi with an S32.
//How many stars we have in the file myCount= dAtof( buffer ); // <-- This aint working Con::printf("myCount= %f",myCount); starCount = dAtoi( buffer ); // <-- This aint working Con::printf("myCount= %d",myCount);This doesn't work because it should be this:
//How many stars we have in the file myCount= dAtoi( buffer ); // <-- This aint working Con::printf("myCount= %d",myCount); starCount = dAtoi( buffer ); // <-- This aint working Con::printf("starCount = %d",starCount );