Category : C Source Code
Archive   : CSRC2.ZIP
Filename : STRNCM.C

 
Output of file : STRNCM.C contained in archive : CSRC2.ZIP
/*
* s t r n c m . c
*/

/*)LIBRARY
*/

#ifdef DOCUMENTATION


title strncmp String Compare With Count
index String compare with count

synopsis
.s.nf
int
strncmp(s1, s2, count);
char *s1;
char *s2;
unsigned int count;
.s.f
Description

Compare at most count bytes between two strings, returning:

-1 if s1 < s2
0 if s1 == s2
+1 if s1 > s2

Bugs

#endif

#define EOS 0

int
strncmp(s1, s2, count)
register char *s1;
register char *s2;
register unsigned int count;
/*
* Compare strings, at most count bytes.
*/
{
if (count == 0)
return (0);
else {
while (*s1++ == *s2) {
if (*s2++ == EOS || --count <= 0)
return (0);
}
return ((s1[-1] < *s2) ? -1 : 1); /* Unequal */
}
}


  3 Responses to “Category : C Source Code
Archive   : CSRC2.ZIP
Filename : STRNCM.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/