Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,606 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Char Comparing #375782
06/27/11 22:05
06/27/11 22:05
Joined: Feb 2009
Posts: 52
Rohiaw Offline OP
Junior Member
Rohiaw  Offline OP
Junior Member

Joined: Feb 2009
Posts: 52
Just a very quick question ...

how do i compare char arrays (char*) ?
is there is an engine function ?
if not [in which case i will have to write it myself], how do i retrieve the length of a char array ?

Thanks wink

Re: Char Comparing [Re: Rohiaw] #375789
06/27/11 22:31
06/27/11 22:31
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
strcmp compares char arrays, strlen returns length.
http://www.cplusplus.com/reference/clibrary/cstring/strcmp/

include stdio.h


3333333333
Re: Char Comparing [Re: Quad] #375875
06/28/11 16:42
06/28/11 16:42
Joined: Feb 2009
Posts: 52
Rohiaw Offline OP
Junior Member
Rohiaw  Offline OP
Junior Member

Joined: Feb 2009
Posts: 52
also ... is there a reason why the compiler doesnt find the strchr function ?

Re: Char Comparing [Re: Rohiaw] #375879
06/28/11 17:18
06/28/11 17:18
Joined: May 2008
Posts: 257
D
djfeeler Offline
Member
djfeeler  Offline
Member
D

Joined: May 2008
Posts: 257
The fonction is str_chr not strchr

Re: Char Comparing [Re: djfeeler] #375882
06/28/11 17:43
06/28/11 17:43
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Not the one from the standard C library.

@Rohiaw: I have no chance to test it right now, but try if this works:
Code:
const char * __cdecl strchr(const char *, int);




Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Char Comparing [Re: WretchedSid] #375946
06/28/11 22:04
06/28/11 22:04
Joined: Feb 2009
Posts: 52
Rohiaw Offline OP
Junior Member
Rohiaw  Offline OP
Junior Member

Joined: Feb 2009
Posts: 52
gave me a crash ...

In case this helps:

Click to reveal..

This is my current code:
Code:
const char * __cdecl strchr(const char *, int);

function checkCommand(char* command){
	char* ch = strchr(command,' ');
	printf("Result: %s",ch);
}




In case you even care:

Click to reveal..

What i want is to do this:

Code:
function checkCommand(char* command){
	// Check space locations
	// Split string into parts
	// Compare each part and perform action
}



Such that if i pass "player health 50" as the parameter
the function splits it up into:
1: "player"
2: "health"
3: "50"
and (obviously) add 50 to player health.

My only problem is that i am not really familiar with Lite-C string manipulation :S
I got this working in java. Having a lot of trouble finding the methods to translate into L-C ...


Re: Char Comparing [Re: Rohiaw] #375991
06/29/11 08:30
06/29/11 08:30
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
You might want to check out Lite Foundation which has a powerful string class which should help you to solve the problem. Here is the documentation for the class so you can check if it has everything you need: http://widerwille.com/litefoundation/reference/group___l_f_string_ref.html

Download link: http://widerwille.com/litefoundation/litefoundation.zip


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Char Comparing [Re: WretchedSid] #376003
06/29/11 10:19
06/29/11 10:19
Joined: Feb 2011
Posts: 135
Myrkling Offline
Member
Myrkling  Offline
Member

Joined: Feb 2011
Posts: 135
Rohiaw, you can also use the STRING struct which comes with Gamestudio (look for STRING in the manual).
STRING is, however, by far not as powerful as the string class of Lite Foundation.

Re: Char Comparing [Re: Myrkling] #376160
06/30/11 14:00
06/30/11 14:00
Joined: Feb 2009
Posts: 52
Rohiaw Offline OP
Junior Member
Rohiaw  Offline OP
Junior Member

Joined: Feb 2009
Posts: 52
I had a problem with the Lite foundation.
i copied the 'sourc'e folder from the lite foundation into my project folder and included "Source\LiteFoundation.h".
Compiler gave me an error:

'source\lfbase.h' line 95 syntax error

typedef signed charint8_t;

Re: Char Comparing [Re: Rohiaw] #376170
06/30/11 14:55
06/30/11 14:55
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Ah yes, thats a problem with the stdio.h header which defines size_t too. The compiler complains about the wrong line.
Open LFBase.h and remove this line (98):
Code:
typedef uint32_t size_t;



Btw, for your problem you will most likely want to use the LFStringComponentsSeperatedByString() function to get an array of the components of your string (the separator would be " ") and then use an LFEnumerator to iterate through the array. Feel free to ask if there are any problems.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Page 1 of 2 1 2

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

Gamestudio download | 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