|
3 registered members (Grant, TipmyPip, 1 invisible),
4,779
guests, and 0
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Char Comparing
#375782
06/27/11 22:05
06/27/11 22:05
|
Joined: Feb 2009
Posts: 52
Rohiaw
OP
Junior Member
|
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 
|
|
|
Re: Char Comparing
[Re: djfeeler]
#375882
06/28/11 17:43
06/28/11 17:43
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
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:
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
OP
Junior Member
|
OP
Junior Member
Joined: Feb 2009
Posts: 52
|
gave me a crash ... In case this helps: This is my current 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: What i want is to do this:
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]
#376170
06/30/11 14:55
06/30/11 14:55
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
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): 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
|
|
|
|