Quote:
strcmp(const char *s, const char *t ) {
for( ; *s == *t; s++, t++ )
if( *s == '\0' )
return 0;
return (*s - *t);
}
I'm not really sure if this strcmp() function is really good...
It's the right idea, but I wouldn't increment the "original" strings since this may cause problems...
for example:
Code:
int isEqual;
char bla[] = "Hello";
char bla2[] = "Hello2";
printf("*bla = %c\n", *bla);
isEqual = strcmp(bla, bla2);
printf("*bla = %c\n", *bla);
The first printf() call would print a 'H' as it should. The second call would print a 'o' since you modified the pointer by incrementing it...
better is:
Code:
int strcmp(const char *s, const char *t)
{
char *sPointer = s, *tPointer = t;
for (...)
...
}
best regards,
A. Blessing