Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 533 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Array of strings and size #472351
04/22/18 21:01
04/22/18 21:01
Joined: Apr 2018
Posts: 37
S
sdelatorre Offline OP
Newbie
sdelatorre  Offline OP
Newbie
S

Joined: Apr 2018
Posts: 37

Hello,

I need array of strings but it's not posible Access to it,

char *p[3]={"EUR","USD","AUD"}

when I Access p[1] it's null but I can do : p[1]="EUR" and shows the correct element. I testes for string [] but its no correct..


I can't get the size ...

Sorry I want only an array of strings and I want get the size for a loop

p[3]={"EUR","USD","AUD"}
while i<size(p) do

how can I do it ?

Re: Array of strings and size [Re: sdelatorre] #472353
04/22/18 21:58
04/22/18 21:58
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Hi!

This might not be the best solution, but this is how I handle such stuff:
Code:
var total_str = 0;

STRING *list_str[999];

void add_to_str(STRING *str){
	
	list_str[total_str] = str_create(str);
	total_str++;
	
}

void test_list(scancode){
	
	if(scancode == 2){ add_to_str("EUR"); }
	if(scancode == 3){ add_to_str("USD"); }
	if(scancode == 4){ add_to_str("AUD"); }
	
}

void main(){
	
	on_1 = test_list; // add EUR to list
	on_2 = test_list; // add USD to list
	on_3 = test_list; // add AUD to list
	
	int i = 0;
	
	while(!key_esc){
		
		// show total amount of strings
		DEBUG_VAR(total_str, 10);
		
		// cycle through all list and show it's elements
		for(i = 0; i < total_str; i++){
			
			draw_text(list_str[i], 10, 30 + 20 * i, COLOR_WHITE);
			
		}
		
		wait(1);
		
	}
	
}



Best regards!

Edit: or version with a structure, so you could create lists:
Code:
typedef struct {
	
	var array_size;	
	STRING *str[999];
	
} LIST;

LIST *currency;

void add_to_str(LIST *pointer, STRING *str){
	
	pointer->str[pointer->array_size] = str_create(str);
	pointer->array_size++;
	
}

void test_currency(scancode){
	
	if(!currency){ currency = sys_nxalloc(sizeof(LIST)); }
	
	if(scancode == 2){ add_to_str(currency, "EUR"); }
	if(scancode == 3){ add_to_str(currency, "USD"); }
	if(scancode == 4){ add_to_str(currency, "AUD"); }
	
}

void main(){
	
	on_1 = test_currency; // add EUR to list
	on_2 = test_currency; // add USD to list
	on_3 = test_currency; // add AUD to list
	
	int i = 0;
	
	while(!key_esc){
		
		// if currency exist ?
		if(currency){
			
			// show total amount of strings
			DEBUG_VAR(currency->array_size, 10);
			
			// cycle through all list and show it's elements
			for(i = 0; i < currency->array_size; i++){
				
				draw_text(currency->str[i], 10, 30 + 20 * i, COLOR_WHITE);
				
			}
			
		}
		
		wait(1);
		
	}
	
}

It would be cool to add initialisation inside of the 'add_to_str' function, but I couldn't get it working..


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Array of strings and size [Re: 3run] #472361
04/23/18 08:47
04/23/18 08:47
Joined: Apr 2018
Posts: 37
S
sdelatorre Offline OP
Newbie
sdelatorre  Offline OP
Newbie
S

Joined: Apr 2018
Posts: 37

Thanks, but

I want only an array of strings and the size of this string....all that for this?

Re: Array of strings and size [Re: sdelatorre] #472365
04/23/18 09:47
04/23/18 09:47
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: sdelatorre

Thanks, but

I want only an array of strings and the size of this string....all that for this?
This is list of arrays and it's size is 'total_str'.
Code:
var total_str = 0;

STRING *list_str[999];

void add_to_str(STRING *str){
	
	list_str[total_str] = str_create(str);
	total_str++;
	
}

void test_list(scancode){
	
	if(scancode == 2){ add_to_str("EUR"); }
	if(scancode == 3){ add_to_str("USD"); }
	if(scancode == 4){ add_to_str("AUD"); }
	
}

void main(){
	
	on_1 = test_list; // add EUR to list
	on_2 = test_list; // add USD to list
	on_3 = test_list; // add AUD to list
	
	int i = 0;
	
	while(!key_esc){
		
		// show total amount of strings
		DEBUG_VAR(total_str, 10);
		
		// cycle through all list and show it's elements
		for(i = 0; i < total_str; i++){
			
			draw_text(list_str[i], 10, 30 + 20 * i, COLOR_WHITE);
			
		}
		
		wait(1);
		
	}
	
}



Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Array of strings and size [Re: 3run] #472366
04/23/18 10:36
04/23/18 10:36
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Do you like risk?

Code:
#define SIZE_OF_CURRENCIES  (((long)&chrCurLast - (long)&chrCur00) / sizeof(char*))
char *chrCur00      = "EUR"; // 
char *chrCur01      = "USD";
char *chrCur02      = "AUD";
char *chrCurLast    = "";

int _i = 0;
for (; _i<SIZE_OF_CURRENCIES; _i+=1) {
	char *_chrCur = *(&chrCur00 + _i);



grin

edited_______________

or with no index at all

Code:
char **_chrCur = &chrCur00;
for (; _chrCur<&chrCurLast; _chrCur+=1) {
...



Just noticed global variables are sorted alphabetically.

edited 2 _______________________

Just realized that you might build the array into a struct with no risk at all.

Code:
typedef struct {
	char *c00;
	char *c01;
	char *c02;
} CURRENCIES;

CURRENCIES *currencies = {
	c00 = "EUR";
	c01 = "USD";
	c02 = "AUD";
}

char **_chrCur = (char**)currencies;
char **_chrCurLast = _chrCur + sizeof(CURRENCIES) / sizeof(char*);
for (; _chrCur<_chrCurLast; _chrCur+=1) {


Re: Array of strings and size [Re: txesmi] #472368
04/23/18 10:45
04/23/18 10:45
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
grin


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1