Strange "delete" effect in typewritting text? :)

Non-platform specific questions.

Strange "delete" effect in typewritting text? :)

Postby Hblade » Sun Mar 24, 2013 5:49 am

So heres my code
Code: Select all
void setText(char msg[256])
{
    int i;
    int tmp = strlen(msg);
    while(i<tmp)
    {
        i++;
        strcpy(text, &msg[i]);
        break;
    }
}


When I use this code, the typewritting works lol but it stamps the whole message and deletes it instead of types it
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Strange "delete" effect in typewritting text? :)

Postby skydereign » Sun Mar 24, 2013 8:38 am

First off, why have the loop? The break statement will always break out of it, so just use an if. Second, each time you call that function it increases i by 1, and then sets text equal to the string starting at msg[i]. So when i is equal to 0, it shows the entire string, when i is equal to 1, it shows all but the first letter, and so on.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Strange "delete" effect in typewritting text? :)

Postby Hblade » Sun Mar 24, 2013 3:13 pm

Alright, I'll use an if statement, and thanks! =) now I know what I have to do... well sort of :) I managed to get it to not go backwards, but instead it types the last letter first haha which is ok I can figure it out from here I think

Thanks sky
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Strange "delete" effect in typewritting text? :)

Postby lcl » Sun Mar 24, 2013 3:18 pm

You could use strcat() for adding the characters to the text one by one.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Strange "delete" effect in typewritting text? :)

Postby Hblade » Mon Mar 25, 2013 1:47 am

I'm just using yours :P
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron