Tuesday 11 December 2012

Implement strncmp

/*This program will compare the n-bit of a string s1 with s2. If both string are same up to n-bits it will return Zero else it will returns the difference of the ascii value of 1st unmatched character.*/

int mystrncmp(const char *s1, const char *s2, int n)

{

while(s1 != '\0' && (*s1++ == *s2++) && --n > 1)

;

return (*s1 - *s2);

}

No comments:

Post a Comment