RAD Studio
ContentsIndex
PreviousUpNext
strncmpi, wcsncmpi

Header File 

string.h  

Category 

Memory and String Manipulation Routines 

Prototype 

int strncmpi(const char *s1, const char *s2, size_t n); 

int wcsncmpi(const wchar_t *s1, const wchar_t *s2, size_t n); 

Description 

Compares a portion of one string to a portion of another, without case sensitivity. 

strncmpi performs a signed comparison of s1 to s2, for a maximum length of n bytes, starting with the first character in each string and continuing with subsequent characters until the corresponding characters differ or until n characters have been examined. The comparison is not case sensitive. (strncmpi is the same as strnicmp--implemented as a macro). It returns a value (< 0, 0, or > 0) based on the result of comparing s1 (or part of it) to s2 (or part of it). 

The routines strnicmp and strncmpi are the same; strncmpi is implemented through a macro in string.h that translates calls from strncmpi to strnicmp. Therefore, in order to use strncmpi, you must include the header file string.h for the macro to be available. This macro is provided for compatibility with other C compilers. 

Return Value  

less than s2 
< 0 
the same as s2 
== 0 
greater than s2 
> 0 

Example

#include <string.h>
#include <stdio.h>
int main(void)
{
   char *buf1 = "BBBccc", *buf2 = "bbbccc";
   int ptr;
   ptr = strncmpi(buf2,buf1,3);
   if (ptr > 0)
      printf("buffer 2 is greater than buffer 1\n");
   if (ptr < 0)
      printf("buffer 2 is less than buffer 1\n");
   if (ptr == 0)
      printf("buffer 2 equals buffer 1\n");
   return 0;
}

Portability

 
POSIX 
Win32 
ANSI C 
ANSI C++ 
strncmpi 
 
 
 
wcsncmpi 
 
 
 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!