Backspace not working? "\b" [CAN ANYONE ANSWERE? >.>]

Non-platform specific questions.

Re: Backspace not working? "\b" [CAN ANYONE ANSWERE? >.>]

Postby makslane » Thu Sep 03, 2009 1:22 am

The easiest way would be
Code: Select all
text[strlen(text)-1] = 0;
but doesn't works due an error (or security restriction) in the code.
So, you can use:

Code: Select all
strcpy(&text[strlen(text)-1], "");
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: Backspace not working? "\b" [CAN ANYONE ANSWERE? >.>]

Postby Hblade » Thu Sep 03, 2009 1:46 am

Thanks, it works perfectly! :D
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: Backspace not working? "\b" [CAN ANYONE ANSWERE? >.>]

Postby JoeLopez » Mon May 26, 2014 9:07 pm

strcpy(&text[strlen(text)-1], "")

Just out of interest, what does the "&" in this code do?
JoeLopez
 
Posts: 4
Joined: Fri May 02, 2014 1:47 am
Score: 0 Give a positive score

Re: Backspace not working? "\b" [CAN ANYONE ANSWERE? >.>]

Postby skydereign » Mon May 26, 2014 9:40 pm

It is used to return an address to a variable. There's this concept of pointers that instead of normal variables you can have a variable that stores the location in memory of another variable. In this case he is converting a char into a char* so you he can use strcpy on it.
Code: Select all
int int_normal = 20;
int* int_pointer = &int_normal; // the & will return the pointer version of the variable
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Backspace not working? "\b" [CAN ANYONE ANSWERE? >.>]

Postby digiot » Mon May 26, 2014 10:01 pm

Sky was fast as light, here is annother explanation, hiding the pointer part a little :

If you put the "&" in front of a variable, you got not its value, but its adress.
That's the reason, why it's called the adress-operator.
In this case, from the char-array "text", or call it a string, it takes the
length (strlen) of the char-array -1(skipping the end mark), and takes the adress
of that char (the last one), and puts in there a "" (no char at all) with the
strcpy-function, i.e. the last char is beeing deleted.
OMG, hope you can understand my messy explanation,


Cheers !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

Re: Backspace not working? "\b" [CAN ANYONE ANSWERE? >.>]

Postby JoeLopez » Tue May 27, 2014 11:57 am

Thanks for the explanations guys. So you are saying that we copy the char "" to the address of the variable, not the name of the variable? What is the difference and why do we do it here an not at other times like strcpy(actor1.text, actor2.text)?
JoeLopez
 
Posts: 4
Joined: Fri May 02, 2014 1:47 am
Score: 0 Give a positive score

Re: Backspace not working? "\b" [CAN ANYONE ANSWERE? >.>]

Postby digiot » Tue May 27, 2014 1:23 pm

JoeLopez wrote:So you are saying that we copy the char "" to the address of the variable,
not the name of the variable?

No, that's the "trick".
If you have one char, it can hold one(!) char, number or sign, you find on
your keyboard, e.g. a, G, %, 5.
But this variable, called text[], is an array(!) of chars, the only way to
get strings in C.
A string is simply a chain of chars, e.g. String, GE1.4, *§&?!.
In C, such string is an array of chars plus the mark for its end, i.e.
s,t,r,i,n,g,\0(there are 2 chars, but it's read as one!). Thats the reason,
why you have to declare the array at least one char larger as needed, char text[7]
in this case.
In this array, every char has its own adress, s-1, t-2, r-3 etc., up to g-6.
If you knew, how long the text array is, it would be easy, to access the
last char with text[6].
In the Backspace-code, you first have to measure the length of the string,
cut of the end mark (-1), and then replace the last char by a whitespace("").
It seems, that the easy way with text[strlen(text)-1] = 0 (or = "") does
not work in GE, so you have to use the workaround with the strcpy-function,
telling it the adress of the char, you want to overwrite.
The adress of the variable instead is the first char !
Hope I have put it right,

About the usage of text actors, I can't say anything.

Cheers !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron