Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (howardR, 7th_zorro), 893 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Check chars in a string with switch command... Solved #421928
04/28/13 10:06
04/28/13 10:06
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
hi and sorry for my english

I want to create a function that check the characters one by one of a string
with switch command ... But i received errors

Code:
STRING* g_str = " ";

...
...

function f_check_str(STRING* l_str)
{
   switch(l_str[1])
   {
        case 'a':
        { ..... }
        break;
    } 
}

....
....

str_cpy(g_str, "filos");
f_check_str(g_str);

...
...



Thx all.

Best Regards.
Dimitris.

Last edited by NeoJT; 04/29/13 07:39.
Re: Check chars in a string with switch command... Help [Re: NeoJT] #421929
04/28/13 10:30
04/28/13 10:30
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Hi, I'm not sure, but try this:
Code:
STRING* tempStr = "#999";

function checkStr(STRING* str){
	// get amount of characters in the string:
	var char_amount = str_len(str);
	// init for loop:
	var i = 0;
	// run for loop, throw all characters:
	for(i = 0; i < char_amount; i ++){
		// get the character number here:
		var char_id = str_getchr(str, i);
		// run the switch statement to find the proper char:
		switch(char_id){
			// if we find (a) character:
			case 97: {
				// found [a] character:
				printf("Found [a] Character!");
				break;
			}		
			default:{
				break;
			}
		}
	}
}

void main(){
	checkStr("Blah");
}

Please note, that it uses ASCII number of the character (look at the manual), and capital letters have different ID then usual ones.
And as well, you'll need to insert all of the characters, by their ID into the switch case... But this is all dirty. Well, this is just an example.


Greets


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Check chars in a string with switch command... Help [Re: NeoJT] #421930
04/28/13 10:41
04/28/13 10:41
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
I want to help you... But you didn't provide the error message.

Re: Check chars in a string with switch command... Solved [Re: Aku_Aku] #421957
04/29/13 07:19
04/29/13 07:19
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
Hi and sorry for my english...

Thank you my friends for your advice...

i had check your code and finally the function works...

bellow is the code... free for use ... free for all...

this is a function that take a STRING ARRAY and check for one string for examle l_array_str[1]
for invalid characters...

if the character that checked there is inside the cases '...' , continue to next character, and
if goes to end ... return success

if the character that checked there isn't inside the case '...' , terminate the while loop and
return error...

Code:
//------------------------------------------------------------------------------------------
//------------------------------ function f_check_for_invalid_chars
function f_check_for_invalid_chars(STRING** l_array_str)
{
	int l_i = 0;
	int l_temp_1_int;
	int l_temp_2_int;
	
	STRING* l_temp_1_str = " ";
	char l_chr = ' ';
	
	bool l_while_stop_bool;
	
	l_temp_1_str = l_array_str[1];
	l_temp_2_int = str_len(l_temp_1_str);
	
	l_i = 1;
	l_while_stop_bool = false;
	
	while ( (l_i <= l_temp_2_int ) && (l_while_stop_bool == false) )
	{
		l_temp_1_int = 0;
		l_chr = str_getchr(l_temp_1_str, l_i);
		switch( l_chr )
		{
			case 'Q':
			case 'W':
			case 'E':
			case 'R':
			case 'T':
			case 'Y':
			case 'U':
			case 'I':
			case 'O':
			case 'P':
				
			case 'A':
			case 'S':
			case 'D':
			case 'F':
			case 'G':
			case 'H':
			case 'J':
			case 'K':
			case 'L':
				
			case 'Z':
			case 'X':
			case 'C':
			case 'V':
			case 'B':
			case 'N':
			case 'M':
			
			case 'q':
			case 'w':
			case 'e':
			case 'r':
			case 't':
			case 'y':
			case 'u':
			case 'i':
			case 'o':
			case 'p':
			
			case 'a':
			case 's':
			case 'd':
			case 'f':
			case 'g':
			case 'h':
			case 'j':
			case 'k':
			case 'l':
			
			case 'z':
			case 'x':
			case 'c':
			case 'v':
			case 'b':
			case 'n':
			case 'm':

			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
			case '0':
			{
				l_temp_1_int = 1;
			}
			break;
		}
		if (l_temp_1_int == 1)
		{
			l_i++;
		}
		else
		{
			l_while_stop_bool = true;
		}
		
	}
	
	if (l_while_stop_bool == true)
	{
		printf("Invalid Name");
		return -2;
	}
	else
	{
		printf("Name was saved");
		return 1;
	}
}



txk you all... and for all...
Best Regards.
Dimitris.

Last edited by NeoJT; 04/29/13 07:38.
Re: Check chars in a string with switch command... Solved [Re: NeoJT] #421966
04/29/13 12:18
04/29/13 12:18
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Code:
if ((l_chr >= 'A' && l_chr <= 'Z') || (l_chr >= 'a' && l_chr <= 'z') || (l_chr >= '0' && l_chr <= '9'))
    l_temp_1_int = 1;


Just as a suggestion.


Always learn from history, to be sure you make the same mistakes again...
Re: Check chars in a string with switch command... Solved [Re: Uhrwerk] #421974
04/29/13 14:43
04/29/13 14:43
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
Hi...

You're absolutely right Uhrwerk. :-)
your code fits better in my code.


Code:
//------------------------------------------------------------------------------------------
//------------------------------ function f_check_for_invalid_chars
function f_check_for_invalid_chars(STRING** l_array_str)
{
	int l_i = 0;
	int l_temp_1_int;
	int l_temp_2_int;
	
	STRING* l_temp_1_str = " ";
	char l_chr = ' ';
	
	bool l_while_stop_bool;
	
	l_temp_1_str = l_array_str[1];
	l_temp_2_int = str_len(l_temp_1_str);
	
	l_i = 1;
	l_while_stop_bool = false;
	
	while ( (l_i <= l_temp_2_int ) && (l_while_stop_bool == false) )
	{
		l_temp_1_int = 0;
		l_chr = str_getchr(l_temp_1_str, l_i);
		
                if (  (l_chr >= 'A' && l_chr <= 'Z') || 
                      (l_chr >= 'a' && l_chr <= 'z') || 
                      (l_chr >= '0' && l_chr <= '9')  )
                {
                    l_temp_1_int = 1;
                }

		if (l_temp_1_int == 1)
		{
			l_i++;
		}
		else
		{
			l_while_stop_bool = true;
		}
		
	}
	
	if (l_while_stop_bool == true)
	{
		printf("Invalid Name");
		return -2;
	}
	else
	{
		printf("Name was saved");
		return 1;
	}
}



thx you all...

Best Regards.
Dimitris.

Last edited by NeoJT; 04/29/13 14:46.
Re: Check chars in a string with switch command... Solved [Re: NeoJT] #421983
04/29/13 20:40
04/29/13 20:40
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
You can also get rid of one if block and the l_temp_1_int variable:
Code:
while ( (l_i <= l_temp_2_int ) && (l_while_stop_bool == false) )
{
	l_temp_1_int = 0;
	l_chr = str_getchr(l_temp_1_str, l_i);
	
	if ((l_chr >= 'A' && l_chr <= 'Z') || 
	    (l_chr >= 'a' && l_chr <= 'z') || 
	    (l_chr >= '0' && l_chr <= '9')  )
	{
		l_i++;
	} else {
		l_while_stop_bool = true;
	}
}



Always learn from history, to be sure you make the same mistakes again...

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