Encoders
>
More...
>
C
>
Program
/* Function strncmp(s,t,n) to compare at most n characters and return the
difference of the characters at the first position where s and t
disagree. (using pointers) */
#include <stdio.h>
int strncmp(char *s, char *t, int n);
main()
{
printf("%d\n",strncmp("hello","hello world",5));
}
int strncmp(char *s, char *t, int n)
{
for(; *s==*t && (*s || *t) && --n; s++,t++)
;
return *s - *t;
}
|