Raised This Month: $ Target: $400
 0% 

Problem with Sizeof


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 04-11-2009 , 13:45   Problem with Sizeof
Reply With Quote #1

My code
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Nowy Plugin"
#define VERSION "1.0"
#define AUTHOR "Sn!ff3r"

new array[][] = {
    
"text one",
    
"text two",
    
"text three"    
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public function()
{
        new 
size_of_first_strin sizeof array[0] - 1    

Error
Code:
Error: Expected token: "]", but found "-integer value-" on line 22
WTF?!
__________________
Join US - custom Zombie Server - Custom Addons:



Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 04-11-2009 , 13:59   Re: Problem with Sizeof
Reply With Quote #2

sizeof is used to find the size in chars of a string in Pawn, I believe.
Spunky is offline
Send a message via AIM to Spunky
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-11-2009 , 14:00   Re: Problem with Sizeof
Reply With Quote #3

sizeof will not work in that fashion.

You can use strlen( array[0] )

From Pawn language guide:
Code:
• Arrays and the sizeof operator
The sizeof operator returns the size of a variable in “elements”. For a
simple (non-compound) variable, the result of sizeof is always 1, because an
element is a cell for a simple variable.

An array with one dimension holds a number of cells and the sizeof operator
returns that number. The snippet below would therefore print “5” at the
display, because the array “msg” holds four characters (each in one cell) plus
a zero-terminator:

Listing: sizeof operator
new msg[] = "Help"
printf("%d", sizeof msg);

With multi-dimensional arrays, the sizeof operator can return the number
of elements in each dimension. For the last (minor) dimension, an element
will again be a cell, but for the major dimension(s), an element is a sub-array.
In the following code snippet, observe that the syntax sizeof matrix refers
to the major dimension of the two-dimensional array and the syntax sizeof
matrix[] refers to the minor dimension of the array. The values that this
snippet prints are 3 and 2 (for the major and minor dimensions respectively):

Listing: sizeof operator and multidimensional arrays

new matrix[3][2] = { { 1, 2 }, { 3, 4 }, { 5, 6 } }
printf("%d %d", sizeof matrix, sizeof matrix[]);
__________________
Bugsy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-11-2009 , 14:48   Re: Problem with Sizeof
Reply With Quote #4

sizeof MyArray[] ; if array is : MyArray[][]

[edit] : Ah you want the size of one specific string ? You have to use strlen.

Last edited by Arkshine; 04-11-2009 at 14:51.
Arkshine is offline
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 04-11-2009 , 16:12   Re: Problem with Sizeof
Reply With Quote #5

Quote:
[edit] : Ah you want the size of one specific string ? You have to use strlen.
Thanks.
__________________
Join US - custom Zombie Server - Custom Addons:



Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
Reply



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

Forum Jump


All times are GMT -4. The time now is 02:22.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode