Jump to content
  • Advertisement
Sign in to follow this  
chxfryer

Backspace problem **SOLVED**

This topic is 4809 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

Basically, im trying to add text input into a game. Im using Direct Input to fill a string "tex" with text. That works fine. What Im trying to implement is a backspace. Anyone have any idea on how to do this? I've tried this... tex was new'd with 100 chars and has text in it. if (stricmp(te,"BACK")==0) { char *temp = new char[strlen(tex)-1]; int i; strcpy(temp,""); for (i = 0; i < strlen(tex)-1; i++) { temp = tex; } strcpy(tex,""); strcpy(tex,temp); delete [] temp; } It works, but if I press backspace multiple times, it starts adding garbage to my tex. By garbage i mean random ascii chars. Any ideas on a better way or why this doesn't work would be appreciated. thanks [Edited by - chxfryer on September 13, 2005 3:00:01 PM]

Share this post


Link to post
Share on other sites
Advertisement
I would use a std::string and its iterator to move through the string. Then you can use erase() and insert() to manage the characters.

ace

Share this post


Link to post
Share on other sites
Solved it, after an hour of rage.

For future reference this is how it did it..

if (stricmp(te,"BACK")==0)
{
int i;
char t2[100];

memset(&t2,0,sizeof(t2));

for (i = 0; i < (int)strlen(tex)-1; i++)
{
t2 = tex;
}
strcpy(tex,"");
strcpy(tex,(char *)t2);
}

Share this post


Link to post
Share on other sites
messy example code #1:

void ro_textinput::bkspace(){
//
// delete 1 char behind cursor
//
char *buf2;
buf2=(char *)malloc(CMDLEN);
bzero(buf2,cmdlen);
if (ticursor==txt){
// if cursor at beginning
return;
}
strcpy(buf2,ticursor);
strcpy(ticursor-1,buf2);
ticursor--;
free(buf2);
}



and #2:


template <typename T,typename F>
void textinput<T,F>::bkspc(){

if (cursor!=0){
string s=stored_text->str();
cursor--;
s.erase(cursor,1);
stored_text->str(s);
tcursor->reset();
}
}

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!