OzBob wrote:
> Am performing the following check to determine if a set of text is at the
> start of a string,....
>
> /* Check for literal text DD at beginning of string date_format */
> char date_format[24];
> if (strstr(date_format, "DD") != date_format)
> {
> /* perform swap here */
> }
>
> Is there something wrong with the structure here? I know that strstr()
> returns a pointer, and "date_format" is a pointer to the first character of
> the string.
>
> I perform this on Solaris 9 using gcc, and it works. I relocate it to HP-UX
> 11.11 using the generic 'cc' and it gives me compiler warnings.
>
> Is there a good guide for portability out there across platforms and
> compilers? Share and Enjoy, Ian Dennison
strstr() is a Standard library function, so it is present
in all conforming C implementations. My own, personal hunch:
you didn't include <string.h> -- but you didn't show enough
code to support or refute the hunch.
If you're just checking for "DD" at the start of the string,
strstr() will do the job but seems to me to be the wrong tool.
I'd suggest you consider
if (strncmp(date_format, "DD", 2) != 0)
or even
if (date_format[0] != 'D' || date_format[1] != 'D')
--
Eric Sosman
lid