SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 09/05/2020, 12:52 AM   #1
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,739
Reputation: 1686
Default Why does strdel() not actually delete data from an array?

Just wondering if anyone knows the answer.
Assume we have this code:
pawn Code:
new array[] = "Hello there world!";
strdel(array, 2, 11);
This would turn the array into:
Code:
H,e, ,w,o,r,l,d,!,EOS,e, ,w,o,r,l,d,!,EOS
So the "llo there " part is actually deleted. Then ofc that empty space is filled up but appearantly those characters are copied rather than being moved.
Using strdel(array, 0, sizeof(array); would just change the first index of the array to the null terminator, so the "ello there world!" would still remain.

Anyone any idea if there's a specific reason why this is so?


FYI, used this piece of code to check it out after finding out that strdel() used EOS rather than actually deleting the data:
pawn Code:
main()
{
    new array[] = "Hello there world!",
        output[sizeof(array)*3];
       
    strdel(array, 2, 11); //And one time with strdel(array, 0, sizeof(array));
   
    for (new i; i < sizeof(array); i++)
    {
        if (!i)
        {
            if (array[i] != EOS)
            {
                format(output, sizeof(output), "%c", array[i]);
            }
            else
            {
                output = "EOS";
            }
            continue;
        }
        if (array[i] != EOS)
        {
            format(output, sizeof(output), "%s,%c", output, array[i]);
        }
        else
        {
            format(output, sizeof(output), "%s,EOS", output);
        }
    }
    print(output);
}
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 09/05/2020, 01:48 AM   #2
JasonRiggs
Gangsta
 
Join Date: Jul 2016
Location: My bedroom.
Posts: 842
Reputation: 52
Default Re: Why does strdel() not actually delete data from an array?

Are you asking if strdel from the first letter to the last letter in array wouldn't delete it and would just count the first letter as NULL? i guess maybe because your array doesn't have a size?
__________________
JasonRiggs is offline   Reply With Quote
Old 09/05/2020, 02:01 AM   #3
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,739
Reputation: 1686
Default Re: Why does strdel() not actually delete data from an array?

No, it has a size. If you create an array with an initial value and you do 't define the array's size, the compiler will automatically set it to the size required for that string. So in given example, the array size is 18
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 09/05/2020, 10:42 AM   #4
RoboN1X
Huge Clucker
 
RoboN1X's Avatar
 
Join Date: Feb 2011
Location: Indonesia
Posts: 453
Reputation: 145
Default Re: Why does strdel() not actually delete data from an array?

I believe all string functions behave the same, treats every string to end with EOS (if i remember right in the pawn doc)
for instance when you use strlen it will just actually find the first EOS position rather than counting amount of characters in it (if im not wrong). So even using strdel which resulted as you shows will not conflict with strlen or other string include functions.

To be noted that print() and format() you use comes with SA-MP, not pawn natives.

If you really wish to clean array data, you would use memcpy or memset instead.
__________________
Need Help? Use Search, WIKI, and FAQ
RoboN1X is offline   Reply With Quote
Old 09/05/2020, 06:27 PM   #5
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,739
Reputation: 1686
Default Re: Why does strdel() not actually delete data from an array?

Any idea yet what manual that was? Because I can't remember reading that anywhere. Thanks tho!

And not needing this for something in particular. Just found it out while helping someone so I got curious. Can't think of a reason to truly clean an array.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql Delete data... daghost111 Scripting Help 2 29/11/2016 03:45 PM
Delete something from array Banditukas Scripting Help 3 26/04/2015 10:47 AM
How To Clear/Delete Data Written in DINI File danish007 Scripting Help 3 10/01/2015 11:14 PM
Unable to edit or delete mysql row data FunnyBear Scripting Help 3 11/11/2014 06:35 AM
Data delete from mysql table? Olvaso42 Scripting Help 2 01/08/2013 10:32 AM


All times are GMT. The time now is 07:48 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.