Char Comparing

Posted By: Rohiaw

Char Comparing - 06/27/11 22:05

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
Posted By: Quad

Re: Char Comparing - 06/27/11 22:31

strcmp compares char arrays, strlen returns length.
http://www.cplusplus.com/reference/clibrary/cstring/strcmp/

include stdio.h
Posted By: Rohiaw

Re: Char Comparing - 06/28/11 16:42

also ... is there a reason why the compiler doesnt find the strchr function ?
Posted By: djfeeler

Re: Char Comparing - 06/28/11 17:18

The fonction is str_chr not strchr
Posted By: WretchedSid

Re: Char Comparing - 06/28/11 17:43

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);


Posted By: Rohiaw

Re: Char Comparing - 06/28/11 22:04

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 ...

Posted By: WretchedSid

Re: Char Comparing - 06/29/11 08:30

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
Posted By: Myrkling

Re: Char Comparing - 06/29/11 10:19

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.
Posted By: Rohiaw

Re: Char Comparing - 06/30/11 14:00

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;
Posted By: WretchedSid

Re: Char Comparing - 06/30/11 14:55

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.
Posted By: Rohiaw

Re: Char Comparing - 07/01/11 19:41

OMG, that function is exactly what I need.
Unfortunately, i got yet another Compiler Error, this time from LTRuntime.h:

Line 81: 'realloc' undeclared identifier

LFProtocolBody **temp = (LFProtocolBody **)realloc(bag->bodys, (bag->bodyCount + 1) * sizeof(LFProtocolBody*));
Posted By: WretchedSid

Re: Char Comparing - 07/01/11 19:58

Uhm, thats strange because it actually should include the window.h header file which includes the realloc function prototype. Three questions:
Can you compile the examples like arrays.c?
What Gamestudio version do you use?
Does the LFBase.h header look like this (the first three actual lines)?
Code:
//#define LF_TARGET_OSX
#define LF_TARGET_WIN32
#define LF_TARGET_LITEC // Needs to be combined with LF_TARGET_WIN32!


Posted By: Rohiaw

Re: Char Comparing - 07/01/11 20:02

The first three lines are exactly like that.
My gamestudio version is 7.02
Arrays.c gave me that same error:

Line 81: 'realloc' undeclared identifier
Posted By: WretchedSid

Re: Char Comparing - 07/01/11 20:10

Ah, okay, the problem is your Gamestudio version, its too old. You should update it, in case that its not an Warez version, or otherwise you should switch to the A8 free version.
Posted By: Rohiaw

Re: Char Comparing - 07/01/11 20:16

Mine is the Development Version. Can i upgrade to the A8 version ?
Cause i believe i tried upgrading once and I got two versions of GameStudio.
A non-working A7 and a free version A8 smirk

But if upgrading to A8 will help me finish my project than i guess I have no choice...
Posted By: WretchedSid

Re: Char Comparing - 07/01/11 20:27

You can download this update for A7 and just install it over your existing version: http://server.conitec.net/down/gstudio7_setup.exe

Then you should apply this patch here which fixes some bugs with the version:
http://server.conitec.net/down/gstudio7_patch.zip

Afterwards, everything should work just fine
Posted By: Rohiaw

Re: Char Comparing - 07/01/11 20:30

No need to update or buy A8 ?
Posted By: WretchedSid

Re: Char Comparing - 07/01/11 20:39

Nope, your A7 should work just fine together with Lite Foundation (I haven't tested it, but the compiler didn't changed much between the later A7 and the earliest A8)
Posted By: Rohiaw

Re: Char Comparing - 07/01/11 20:47

Great. The update is still downloading.
I'll see if it works and post back. Thanks for all the help wink
Posted By: Rohiaw

Re: Char Comparing - 07/09/11 15:56

It didn't work.
I installed the update and the patch, and now i've got a trial version, and instead of just the error i had prior to the update and the patch, i've recieved about 2 compiler errors, and 3 others during gameplay.

I think i prefer my old version >.> at the cost of LF
© 2023 lite-C Forums