Jump to content
  • Advertisement
Sign in to follow this  
patrickpp

Bug in Lesson 14 - text length calculation

This topic is 4097 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I think there is a bug in lesson 14 in the section that calculates the text length of a string. I discovered it because accented characters such as é, à, etc. are not displayed in the example program. In fact, all characters with ASCII code above 128 are not displayed. The reason is a mismatch between signed char and unsigned char Code of lesson 14: char text[256]; --> char data type defaults to signed char in VC ++ (From MSDN: char : –128 to 127) for (unsigned int loop=0;loop<(strlen(text));loop++) // Loop To Find Text Length { length+=gmf[text[loop]].gmfCellIncX; // Increase Length By Each Characters Width } --> for all ASCII codes above 128, text[loop] is a value below 0 --> gmf[text[loop]].gmfCellIncX gives undesired results For example : character "é" (ASCII code 233) --> text[loop] will have -23 as value because the char data type is in fact signed char. Solution: cast the char to an unsigned char unsigned char ch; for (unsigned int loop=0;loop<(strlen(text));loop++) // Loop To Find Text Length { ch = (unsigned char) text[loop]; length+=gmf[ch].gmfCellIncX; // Increase Length By Each Characters Width } --> Now ch will have the correct value 233, and the "é" will be nicely displayed Kind regards, Patrick Pasteels

Share this post


Link to post
Share on other sites
Advertisement
Hi,

Thanks for that information. I'll make the change as soon as our FTP access to the site is back.

Luke.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!