SHAWN ELLIS wrote:
>
> Hi all,
>
> I have the latest version of CCS's PCW compiler and I'm trying to
> compare two strings. I notice the strcmp function is declared:
>
> signed int strcmp(*s1, *s2);
>
> Does this mean that when I call it I must use:
>
> intvar = strcmp(&s1[0], &s2[0]);
>
> In effect passing the address of the FIRST ELEMENT of the string? Or
> is there some other code which must be used to call this function?
>
> Thanks,
Not is necessary the & and [0].
One problem that i found on CCS, is the function strstr. But i have
implemented!
You could do that, but in C the name of a string variable is already a
pointer. Thus for a string declared as "char s1[5]", you could pass its
address as either "s1" or "&s1[0]". It's easier to use the former. Thus
strcmp() can be called with:
intvar = strcmp(s1, s2);
Note that if you wanted to start the comparison from the second character
in both strings, then you would need to declare the addresses
specifically:
> Hi all,
>
> I have the latest version of CCS's PCW compiler and I'm trying to
> compare two strings. I notice the strcmp function is declared:
>
> signed int strcmp(*s1, *s2);
>
> Does this mean that when I call it I must use:
>
> intvar = strcmp(&s1[0], &s2[0]);
>
> In effect passing the address of the FIRST ELEMENT of the string? Or
> is there some other code which must be used to call this function?
>
> Thanks,
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ron Kreymborg Computer Systems Manager
Monash University CRC for Southern Hemisphere Meteorology
Wellington Road
Clayton, VIC 3168 Phone : 061-3-9905-9671
Australia Fax : 061-3-9905-9689
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~