Ok, this has been driving me mad for two days now so I'm turning to you guys for help and/or suggestions. What I have is a text-RPG "engine" that is controlled by a script interpreter that I'm writing. Here's a simple sample script:
//output: "a = 10"
main()
{
var int a = 5 ;
var double b = 4.5 ;
set a 10 ;
prt ' a = &a '
}
This works just fine. However, I was messing around with printing two variables in a string, and when I used a particular string, an unusual anomaly occurred. This is the script I wrote:
//nevermind the poor grammar in prt() - I was being silly :)
main()
{
var int a = 3 ;
var double b = 4.5 ;
prt ' this &a and &b is high '
}
That script should've output "this 3 and 4.5 is high " , but the actual output was this: 4.5 . Instead of printing the string, it printed the value portion of the previous var() statement. I was perplexed. After doing some thinking, I increased the length of the string by one by changing 'is' to 'isa' . And to my amazement, it worked just fine: "this 3 and 4.5 isa high ". So I counted up the number of characters in the offending string, which came out to be 26 characters. So I typed in some random 26 character string and voila! .... it output the same error: 4.5 . So I did some investigating. To make a long story sweet and short, the error is triggered in the deserialization of the prt() function within my script-command stack. The offending code is this:
/*iext is an int, parm is a fixed-length string (no overflow)*/
fread((int*)&iext, sizeof(int), 1, fp);
fread((char*)parm, sizeof(char), iext, fp);
When this code attempts to read in the 26 character string, it fails to read the integer in the first fread(), which is supposed to be 26. I checked the return value, which was zero - so it didn't even read anything. If the length of the string is greater than or less than 26, it always works fine. I can't figure this out. If anyone has any suggestions as to what "might" be happening, please let me know. If more information or code is needed, just ask.
Thank you :)
[Edited by - 3DNeophyte on September 16, 2004 9:51:06 PM]