Suspicious pointer error :D?

Non-platform specific questions.

Suspicious pointer error :D?

Postby Hblade » Mon Nov 14, 2011 2:05 pm

strcpy(CHAONAME, strlen(CHAONAME)-1);

This gives me an error ^^ Anyone mind helping out? I'm trying to make a "backspace" button haha.

Code: Select all

     sprintf(CHAONAME, "%s", strlen(CHAONAME)-1);


This code crashes GE XDD
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: Suspicious pointer error :D?

Postby lcl » Mon Nov 14, 2011 2:44 pm

strlen() returns an integer, not a string, so your code should be:
Code: Select all
sprintf(CHAONAME, "%i", strlen(CHAONAME)-1);

:D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Suspicious pointer error :D?

Postby Hblade » Mon Nov 14, 2011 2:48 pm

lcl wrote:strlen() returns an integer, not a string, so your code should be:
Code: Select all
sprintf(CHAONAME, "%i", strlen(CHAONAME)-1);

:D

Thhhanks! :D +1

Edit: LOL now all it does is change the text actor to "however many letters in the string" XD then 0 O-o
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: Suspicious pointer error :D?

Postby lcl » Mon Nov 14, 2011 2:57 pm

Yeah, lol I understood your problem just after posting that. I'm now solving it for you. :)

EDIT: It first seemed that you wanted just to show the amount of characters and that's why I got confused. :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Suspicious pointer error :D?

Postby lcl » Mon Nov 14, 2011 3:00 pm

Here ya go:
Code: Select all
CHAONAME[strlen(CHAONAME) - 1 * (strlen(CHAONAME) > 0)] = NULL;

The * (strlen(...)) part is for that otherwise it'd try to set CHAONAME[- 1] equal to NULL when strlen is 0. And that naturally causes error.
:)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Suspicious pointer error :D?

Postby Hblade » Mon Nov 14, 2011 3:07 pm

Thanks dood!

but it keeps the first letter D: I think I can fix this though ^^

Well, it keeps it lol but it gets overwritten so its good :D

Thanks a bunch man! :D

Fixed ^^
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: Suspicious pointer error :D?

Postby lcl » Mon Nov 14, 2011 3:09 pm

Hblade wrote:Thanks dood!

but it keeps the first letter D: I think I can fix this though ^^

I found this problem too, but you can get around of it by changing you sprintf() to strcpy(). (The one that shows your CHAONAME. :D)

EDIT:
Thought to explain more accurately.. :D

So, like:
Code: Select all
strcpy(text, CHAONAME);


It seems that for some reason, the sprintf() doesn't work with the actors text all that well compared to strcpy().
I don't really know why it works only with strcpy():

EDIT 2: :lol:
Hblade wrote:Well, it keeps it lol but it gets overwritten so its good

That sounds like spritntf() doesn't refresh the text actors text as it should, because while I was testing my code, another text actor showed that string was empty, but the one I was erasing showed still the first letter..
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Suspicious pointer error :D?

Postby Hblade » Mon Nov 14, 2011 3:46 pm

Yeah but I fixed it now =) I added a simpel if script
Code: Select all
if(strlen(CHAONAME)>0) {
//make chaos name appear }
else {
//eithe rmake the text blank, but in my case change the text to "NO_NAME"
}

the text "NO_NAME" does not effect the CHAONAME varaible =)
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