Game programming

Moderators: None (Apply to moderate this forum)
Number of threads: 2047
Number of posts: 5331

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
DirectX and keyboard input to strings Posted by Dregon on 11 Feb 2000 at 4:40 PM
I'm using DirectX and am trying to create a keyboard handler for string inputs. I need the user to be able to say... type their name, having the letters appear as they type and be able to store them in a string. The problem w/ the way I'm going about it is that I'm storing the users input as char ascii_chr. then trying to place it in char string [40] as in ...<br>
string [0]=ascii_code;<br>
<br>
What am I missing or can you advise me on a better method. <br>
Thanx.<br>
<br>



Edit Report
Re: DirectX and keyboard input to strings Posted by Al Murray on 16 Feb 2000 at 12:37 PM
You will have to elaborate, a little about why that doesn't work. I would do almost exactly the same as you, (although Microsoft might prefer you to use unicode for example, and CStrings if you are in MFC). Watch that if you add a character to the end of a string , that you make the subsequent character a zero, to terminate it, and dont write beyond the end of the array. If you rewrite the string you will have to reset the counter too.<br>
<br>
static int counter;<br>
<br>
void addChar (char newAscii)<br>
{<br>
if (counter==MAX_LEN)<br>
return; // run out of space<br>
string[counter] = newAscii;<br>
string[counter+1] = '\0';<br>
counter++;<br>
}<br>
<br>
//then in the main loop<br>
<br>
//...<br>
char string [MAX_LEN+1]; // extra 1 for terminate<br>
counter = 0;<br>
addChar('h'); // or get from dinput<br>
addChar('e');<br>
printf("%s", string);<br>
printf("String is %ld long", counter);<br>
//...<br>
<br>
I hope this tackles your problem, if not please elaborate<br>






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.