Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
memcmp: compares the first count characters between buf1 and buf2
//Declaration: int memcmp(const void *buf1, const void *buf2, size_t count);
//Return: returns an integer as follows:
< 0 : buf1 is less than buf2
0 : buf1 is equal to buf2
> 0 >: buf1 is greater than buf2
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int outcome, len, l1, l2;
char *str = "asdf";
char *str1 = "asdfasdf";
/* find the length of shortest string */
l1 = strlen(str);
l2 = strlen(str1);
len = l1 < l2 ? l1:l2;
outcome = memcmp(str, str1, len);
if(!outcome)
printf("Equal");
else if(outcome<0)
printf("First less than second.");
else
printf("First greater than second.");
return 0;
}
/*
Equal*/