This topic is now archived and is closed to further replies.


sprintf Question (Weird)

Recommended Posts

Im making a SDL game engine and for the init of the graphics I want to load some information into the screen structure. //the cWidth,cHeight,cBPP are all char[3] //Set Screen structure variables. Screen.Width=Width; sprintf(Screen.cWidth,"%d",Screen.Width); Screen.Height=Height; sprintf(Screen.cHeight,"%i",Screen.Height); Screen.BPP=BPP; sprintf(Screen.cBPP,"%d",Screen.BPP); SDL_VideoDriverName(Screen.VideoDriver,10); It compiles fine but the output is cWidth = 1027688 cHeight=7688 cBPP=8 It should be cWidth=1024, cHeight=768, and cBPP=8 Im think I need to clear some buffer or something because it seems to merge them together. Any ideas?

Share this post

Link to post
Share on other sites
using char[3]: // screen dimensions of 640x480
cHeight[0] = ''4'';
cHeight[1] = ''8'';
cHeight[2] = ''0'';
cHeight[3] = ''\0''; // oops!

Use char[4], at least. Also, any reason why you''re using "%d" in some places and "%i" in others?

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!

Share this post

Link to post
Share on other sites