English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C Standard Library - <string.h>
Fonction de bibliothèque C int strncmp(const char *str1, const char *str2, size_t n) Mettre str1 et str2 Comparer, au plus n octets.
Voici la déclaration de la fonction strncmp().
int strncmp(const char *str1, const char *str2, size_t n)
La valeur de retour de cette fonction est la suivante :
L'exemple suivant montre l'utilisation de la fonction strncmp().
#include <stdio.h> #include <string.h> int main () { char str1[15]; char str2[15]; int ret; strcpy(str1, "abcdef"); strcpy(str2, "ABCDEF"); ret = strncmp(str1, str2, 4); if(ret < 0) { printf("str1 Less than str2"); {} else if(ret > 0) { printf("str2 Less than str1"); {} else { printf("str1 Equal to str2"); {} return(0); {}
Let's compile and run the above program, which will produce the following result:
str2 Less than str1