I am suing the strcmp function from K&R2, page 106 which is used here:
http://clc-wiki.net/wiki/K%26R2_solu...r_5:Exercise_4
I only changed the name to avoid confusion with real strcmp. K&R2 says:
it returns < 0, if s <t, 0 if s== t, 0 if s t.
but I have found, it returns < 0 if s t and vice-versa.
int my_strcmp( char* s, char* t )
{
for(; *s == *t; ++s, ++t )
{
printf("*s = %c\n", *s);
printf("*t = %c\n", *t);
if( *s == '\0' )
{
return 0;
}
}
return *s - *t;
}
int main(void)
{
char s[] = "it is ok";
char t[] = "nope";
printf("comparing <%swith <%s= %d\n", s, t, my_strcmp( s, t ));
return 0;
}
=========== OUTPUT ============
/home/arnuld/programs/C $ gcc -ansi -pedantic -Wall -Wextra 5-5.c
/home/arnuld/programs/C $ ./a.out
comparing <it is okwith <nope= -5
/home/arnuld/programs/C $
--
http://lispmachine.wordpress.com/
Please remove capital 'V's when you reply to me via e-mail.