Page 2 of 2

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

PostPosted: Thu Sep 03, 2009 1:22 am
by makslane
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], "");

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

PostPosted: Thu Sep 03, 2009 1:46 am
by Hblade
Thanks, it works perfectly! :D

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

PostPosted: Mon May 26, 2014 9:07 pm
by JoeLopez
strcpy(&text[strlen(text)-1], "")

Just out of interest, what does the "&" in this code do?

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

PostPosted: Mon May 26, 2014 9:40 pm
by skydereign
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

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

PostPosted: Mon May 26, 2014 10:01 pm
by digiot
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 !

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

PostPosted: Tue May 27, 2014 11:57 am
by JoeLopez
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)?

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

PostPosted: Tue May 27, 2014 1:23 pm
by digiot
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 !