Re: A89: installing C Event Hooks + misc other...


[Prev][Next][Index][Thread]

Re: A89: installing C Event Hooks + misc other...




At 06:15 2001-02-13, you wrote:
>Now on to the misc other...
>How does one include special characters in an array?
>say i have an array like this
>
>char * El[]={
>"Element0",
>"Element1",
>"Elementx"
>};
>
>1. if I wanted to include say a left arrow character (conversion arrow) in
>an element how would i do that?
>Example: "Elem->ent1"  where -> stands for the conversion arrow of course...

Use the \<number> for this. like this: "Elem\22ent1" or whatever ti-ascii 
value the char you want has.

>//isLike(StrToTestForMatch,StrToMatch)
>//all characters in s1 must = len(s1) chars in string s2
>//returns strlen(s2) or 0 (NULL) if no match
>
>unsigned long isLike(const char* s1, const char* s2)
>{
>  unsigned long x=0;
>
>  while(s1[x]==s2[x])
>   x++;
>
>  return x==strlen(s2)?x:0;        //the warning comes from the strlen
>function:
>                                                     //discards qualifiers
>from pointer target type
>                                                     // which would be s2...
>}

Isn't this function a bit strange? What happens if there happens to be two 
identical strings after each other in memory?
like s1 points to one place with
"string1\0string2"
and the other to another place in memory where
"string1\0string2"
is stored.
Then it will return NULL even though the first string is "string1" in both 
and thus identical.
check for null or nonmatching char in the loop, and return
NULL if you didn't stop at null or counter of length (x) if you did or 
something close to that instead.
should be a bit faster too, since you don't have to count the length of the 
string twice as you do now.

while(s2[x]!=0 && s1[x]==s2[x])
  x++;

maybe.

///Olle




Follow-Ups: References: