Raised This Month: $ Target: $400
 0% 

Actual size of array.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nanaka
Junior Member
Join Date: May 2013
Old 05-15-2013 , 10:31   Actual size of array.
Reply With Quote #1

Hello,
Yesterday I started with Amx Mod X and Pawn language.

Let's say that IP in this array is 192.168.1.1 in below example:
Code:
new szIP[128];
get_user_ip(id, szIP, charsmax(szIP));
So, how can I check size of this array?
Sizeof returns 128, but I'm looking for 11, because "192.168.1.1" == 11.

PS. Sorry for my weak english.
Nanaka is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-15-2013 , 10:44   Re: Actual size of array.
Reply With Quote #2

new szIP[128]
->
new szIP[11]
__________________
Kia is offline
Nanaka
Junior Member
Join Date: May 2013
Old 05-15-2013 , 11:08   Re: Actual size of array.
Reply With Quote #3

Quote:
Originally Posted by Kia View Post
new szIP[128]
->
new szIP[11]
Yeah, it would work if I would know from the beggining size of array, but I don't.
192.168.1.1 was only an example.
Nanaka is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-15-2013 , 11:15   Re: Actual size of array.
Reply With Quote #4

Then make it big enough and use szIP[0] to get the whole array.
__________________
Kia is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-15-2013 , 11:50   Re: Actual size of array.
Reply With Quote #5

Quote:
Originally Posted by Kia View Post
Then make it big enough and use szIP[0] to get the whole array.
what? szIP[ 0 ] will return the first character of the string.

To get the current size of the string, use strlen( ).
Backstabnoob is offline
Nanaka
Junior Member
Join Date: May 2013
Old 05-15-2013 , 11:40   Re: Actual size of array.
Reply With Quote #6

Thanks for help.
T/C. Problem solved.
Nanaka is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-15-2013 , 12:20   Re: Actual size of array.
Reply With Quote #7

Aaaaah, whooops, just write it as it is to get the whole array, sorry.
__________________
Kia is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-15-2013 , 13:09   Re: Actual size of array.
Reply With Quote #8

Quote:
Originally Posted by Nanaka View Post
So, how can I check size of this array?
Sizeof returns 128, but I'm looking for 11, because "192.168.1.1" == 11.

PS. Sorry for my weak english.
The "size of the array" will always be 128. The length of the string is what you want using strlen(). Also, you don't need an array that big because the largest IP you can get from that function is 21 so you should dimension the array with 22.
__________________
fysiks is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-15-2013 , 14:33   Re: Actual size of array.
Reply With Quote #9

In fact, you should do
PHP Code:
new szIP[16];
get_user_ip(idszIPcharsmax(szIP), true); 
This will give you an IP without ":<port>" at the end, and the max length of an IP is 15 symbols.
__________________
hleV is offline
Nanaka
Junior Member
Join Date: May 2013
Old 05-15-2013 , 22:35   Re: Actual size of array.
Reply With Quote #10

I did it this way:
PHP Code:
    new szPortIP[64], szIP[32], szPort[6];
get_user_ip(idszPortIPcharsmax(szPortIP));

copyc(szIPcharsmax(szIP), szPortIP':');
copy(szPortcharsmax(szPort), szPortIP[strlen(szIP) + 1]); 
Nanaka is offline
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

Forum Jump


All times are GMT -4. The time now is 16:15.


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