C
C. J. Clegg
I have two null-terminated character strings, str1 and str2. I don't
know which one is longer, but I want to know if the shortest one
(whichever one that might be) matches the first part of the longer
one.
I can say:
if ( strncmp( str1, str2, strlen( str2 ) ) == 0 ||
strncmp( str2, str1, strlen( str1 ) ) == 0 )
but that seems a bit kludgy and inelegant.
Is there a better way?
know which one is longer, but I want to know if the shortest one
(whichever one that might be) matches the first part of the longer
one.
I can say:
if ( strncmp( str1, str2, strlen( str2 ) ) == 0 ||
strncmp( str2, str1, strlen( str1 ) ) == 0 )
but that seems a bit kludgy and inelegant.
Is there a better way?