Borland C++ reference

strncmp, _fstrncmp

raw OCR

Compares a portion of one string to a portion of another.

Defined in header <string.h>

Syntax

#include <string.h>
Near version: int strncmp(const char  *sl, const char *s2, size_t maxlen);
Far version: int far _fstrncmp(const char far *sl,const char far *s2,
                               size_t maxlen)

Portability

DOSUNIXWindowsANSI CC++ only
Near version ■■■■
■■

Remarks

strncmp makes the same unsigned comparison as strcmp, but looks at no more than maxlen characters. It starts with the first character in each string and continues with subsequent characters until the corresponding charac-ters differ or until it has examined maxlen characters.

Return value

strncmp returns an int value based on the result of comparing si (or part of it) to s2 (or part of it).

< 0 if s2 is less than s2 -= 0 if si is the same as s2 > 0 if s2 is greater than s2

See also

Example

#include <string.h>
#include <stdio.h>
int main(void)

   char *bufl = "aaabbb",  *buf2 - "bbbccc", *buf3 = "ccc";
   int ptr;
   ptr = strncmp(buf2,bufl,3 );
   if (ptr > 0)
      printf("buffer 2 is greater  than buffer l\n");
   else
      printf("buffer 2 is less  than buffer l\n");
   ptr = strncmp(buf2,buf3,3) ;
   if (ptr > 0)
      printf("buffer 2 is greater  than buffer 3\n");
   else
   printf("buffer 2 is less than  buffer 3\n";
return(0);

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • heading `strncmp, Jstrncmp` read as `strncmp, _fstrncmp`