Raised This Month: $51 Target: $400
 12% 

Solved String arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 09-29-2017 , 12:28   String arrays
Reply With Quote #1

Hi, how can I make a string array?

Like have an array of names like this:

PHP Code:
char names[] = {"Name 1""Name 2"}
PrintToChatAll("%s is the first, %s is the second."names[0], names[1]); 
__________________

Last edited by condolent; 09-29-2017 at 12:44.
condolent is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 09-29-2017 , 12:43   Re: String arrays
Reply With Quote #2

Strings are arrays too. Use 2d array.
PHP Code:
char names[][] 
Timocop is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 09-29-2017 , 12:46   Re: String arrays
Reply With Quote #3

In Sourcepawn, currently, a string is an array of characters.

So if you want multiple strings, you need multiple arrays. An array of arrays.

PHP Code:
char names[][] = {"Name 1""Name 2"}; 
If you don't know exactly how big one of the dimensions of the array is going to be at compile time (for example, you need an array of MaxClients number of strings) then your declaration of the array should be dynamic.

PHP Code:
char[][] names = new char[numberOfStrings][lengthOfLongestString];
names[0] = "Name 1";
names[1] = "Name 2"
__________________

Last edited by ddhoward; 09-29-2017 at 12:51.
ddhoward is offline
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 13:28.


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