2 Mart 2020 Pazartesi

POSIX strcasecmp metodu

Giriş
Açıklaması şöyle.
The strcase*-functions are not Standard C, but a POSIX extension.
Açıklaması şöyle. Büyük küçük harf farkı dikkate alınmaz.
The strcasecmp() function performs a byte-by-byte comparison of the strings s1 and s2, ignoring the case of the characters. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2.
Önce her ley küçük harfe çevrilir. Açıklaması şöyle.
In the POSIX locale, strcasecmp() and strncasecmp() shall behave as if the strings had been converted to lowercase and then a byte comparison performed. The results are unspecified in other locales.
Örnek
Elimizde şöyle bir kod olsun
#include <stdio.h>
#include <string.h>

int main()
{
  // ASCII values
  // 'A' = 65
  // '_' = 95
  // 'a' = 97
  printf("%i\n", strcmp("A", "_"));
  printf("%i\n", strcmp("a", "_"));
  printf("%i\n", strcasecmp("A", "_"));
  printf("%i\n", strcasecmp("a", "_"));
  return 0;
}
Çıktı olarak şunu alırız
-1  # "A" is less than "_"
1   # "a" is more than "_"
2   # "A" is more than "_" with strcasecmp ???
2   # "a" is more than "_" with strcasecmp

Hiç yorum yok:

Yorum Gönder