Borland C++ reference

strcmp

raw OCR

Compares one string to another.

Defined in header <string.h>

Syntax

#include <string.h>
int strcmp(const char *sl, const char *s2);

Portability

DOSUNIXWindowsANSI CC++ only
■■■■

Remarks

strcmp performs an unsigned comparison of si to s2, starting with the first character in each string and continuing with subsequent characters until the corresponding characters differ or until the end of the strings is reached.

Return value

strcmp returns a value that is < 0 if si is less than s2 == 0 if si is the same as s2 > 0 if si is greater than s2

See also

Example

include  <string.h>
#include <stdio.h>

int main(void)
{
   char *bufl = "aaa",  *buf2 = "bbb", *buf3 = "ccc";
   int ptr;
   ptr = strcmp (buf2, bufl);
   if (ptr > 0)
      printf ("buffer 2 is greater than buffer l\n");
   else
      printf ("buffer 2 is less than buffer l\n");
   ptr = strcmp (buf2, buf3);
   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.