SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 21/02/2020, 09:41 AM   #1
shaneadev
Little Clucker
 
Join Date: Aug 2019
Posts: 43
Reputation: 0
Question EOS Question

Hi.

If I have the following function:
Code:
new gQuery[ 256 ];
gQuery[ 0 ] = EOS;
mysql_format( SQL, gQuery, sizeof gQuery, "INSERT INTO `logs_sanctions` (`Player`, `Type`, `Log`, `By`) VALUES ('%d', '%d', '%s', '%d')", player, type, log, by );
mysql_tquery( SQL, gQuery, "", "" );
Will gQuery be reduced by string length?
Or if someone can give me an example how to use EOS and an explanation.
shaneadev is offline   Reply With Quote
Old 21/02/2020, 10:35 AM   #2
Rolux
Big Clucker
 
Rolux's Avatar
 
Join Date: Jun 2013
Location: u2mu7c7ttj8qt
Posts: 81
Reputation: 20
Default Re: EOS Question

EOS means End Of String.
You can insert it into a string to mark it's end. Like:
Code:
new string[32] = "Hello Wolrd!";
string[5] = EOS;
print(string);
This code will print: "Hello", because everything after the 4th char will get ignored.

With
Code:
gQuery[ 0 ] = EOS;
you are basically emptying the qQuery string.
Rolux is offline   Reply With Quote
Old 21/02/2020, 01:48 PM   #3
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,528
Reputation: 1642
Default Re: EOS Question

I do have to alter a few things on above reply.
Quote:
because everything after the 4th char will get ignored.
Yes.
Quote:
you are basically emptying the qQuery string.
No. You are telling the machine that it is the end of the string. It won't read any data after EOS (also known as the null terminator, '\0'). When you set the first index of the array to EOS, the array you provided will be:
Code:
'\0', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'l', 'r', 'd', '!', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '\0'
Because the EOS was found at the first index it simply won't print the rest of the array.
Try running this code, for example:
pawn Code:
new uselessArray[] = "Hello world";
uselessArray[5] = '\0'; //Or uselessArray[5] = EOS;, or even just uselessArray[5] = 0;

print(uselessArray);
printf("%s", uselessArray[6]);
Note how this array (after assigning the EOS) will be:
Code:
'H', 'e', 'l', 'l', 'o', '\0', 'w', 'o', 'r', 'l', 'd', '\0'
.
Running the code above would print:
Code:
Hello
world
Then the other thing I have to say:
pawn Code:
new string[32] = "Hello Wolrd!";
There is no need to set the array size to 32. As you could see above there are quite some empty cells. Even though it was just an example, you shouldn't send such examples as people are trying to learn here and they could learn themselves bad practice this way.
That being said, if you don't provide the array size combined with setting an initial value, the pre-processor will automatically set the array size. So:
pawn Code:
new array[] = "Hello world";
Will automatically get a size of 12 cells. Note how "Hello world" is 11 characters. This is because the null terminator is always at the end of an array. This is why you can't access the last cell (array index out of bounds). You have access to cell 0 up to 11. 12 is always the null terminator.

EDIT:
FYI, the null terminator is just '0'. I always show it as '\0' so it is more clear that it is the null terminator.
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/
Kwarde is offline   Reply With Quote
Old 21/02/2020, 08:04 PM   #4
shaneadev
Little Clucker
 
Join Date: Aug 2019
Posts: 43
Reputation: 0
Default Re: EOS Question

That's the answer .
Thanks you very much!
shaneadev 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
[QUESTION] Kind a team based question Dirkon Scripting Help 1 24/03/2013 08:05 PM
[Question] 1 very important question... Master_Gangster Help Archive 4 02/03/2011 07:36 PM
Question regarding playerid (noob question!) Mattjones17 Help Archive 5 27/10/2010 04:21 PM
Data type question.. (and mac address question) DarrenReeder Help Archive 2 21/10/2010 08:20 PM
Hello all i got one question (very easy to answer J.I.C question) SAMPfan109 General 0 06/03/2010 04:43 PM


All times are GMT. The time now is 11:43 AM.


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