strins single characters
#1

pawn Код:
new str_hello[16] = "hello";
new str_world[16] = "world";
   
strins(str_world, str_hello[2], 0);
   
// The char in str_hello[2] is a lowercase L.
// I want the lowercase L to be inserted at the start of str_world,
// making it become "lworld". But it inserts the entire string AFTER L.
   
print(str_world);

// Output: 'lloworld'
Please don't suggest format. I want to insert characters at various parts in the string, not always the start/end.
Reply
#2

What strins does is look for a NULL character in the string that is being inserted into another. Think of it like this: the address behind str_hello denotes a location X in the memory, str_hello[2] denotes a location X+2 and strins will start inserting and searching for a \0 character.

I won't suggest format, I'll suggest that you write your own sort of routine for this. Don't be afraid of creating another buffer to store the string, for example, since this is what strins does internally as well, there's no magic behind that.
1. Create an output string.
2. Start a for-loop: i = 0; i != strlen(destination); ++i
3. If i becomes the value at which you want to insert (in your case this is 0, but not always as you said, so make the code generic ), insert the character and increment the value of i (make sure it is not the last character in the string, also see if the character at which you wish to insert is even in the valid range of the string length before the insertion step).
Reply
#3

ITs words from the variable choosen

so in your case you choose to start from after the second letter so its would show the 345 letter..... Thats would i understand it if u wanted the whole word u needed to remove the brackets and you will get hello world

Edit:
// the variable 3 ..... as u can see
will print out... if this is what u talking about
worhellold
strins(str_world, str_hello, 3);
pawn Код:
Edit:
    new str_hello[16] = "dfhgi";
    new str_world[16] = "abcjklm";

    strins(str_world, str_hello, 3);
print(str_world);
//output
"abcdefghijklm"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)