Home > Backend Development > C++ > In C language, what is the difference between memcmp and memicmp functions?

In C language, what is the difference between memcmp and memicmp functions?

WBOY
Release: 2023-09-12 12:57:03
forward
850 people have browsed it

In C language, what is the difference between memcmp and memicmp functions?

Memcmp() and memicmp() compares first n bytes of two blocks of memory.

  • memcmp() performs comparison as unsigned characters.

  • memicmp() performs comparison as characters but, ignore upper case or lower case letters.

  • Both functions return an integer value.

  • Two memory buffers are equal (returns 0).

  • First buffer is greater than second (returns >0).

  • First buffer is less than second(returns

Program

The following program shows the usage of memcmp() and memicmp() functions.

#include<conio.h>
#include<mem.h>
main(){
   char st1[]="This is C Programming language";
   char st2[]="this is c programming";
   int result;
   result=memcmp(st1,st2,strlen(st2));
   printf("</p><p>1. result after comparing buffer using memcmp");
   check(result);
   result=memicmp(st1,st2,strlen(st2));
   printf("</p><p>2. result after comparing buffer using memicmp");
   check(result);
}
check(int x){
   if(x==0)
      printf(" buffer st1 and st2 hold same data</p><p>");
   if(x>0)
      printf("buffer st1 is bigger than buffer st2</p><p>");
   if(x<0)
      printf(&ldquo; buffer st1 is less than buffer st2</p><p>");
}
Copy after login

输出

你将看到以下输出 −

1. result after comparing buffer using memcmp buffer st1 is less than buffer st2
2. result after comparing buffer using memicmp buffer st1 and st2 hold same data
Copy after login

The above is the detailed content of In C language, what is the difference between memcmp and memicmp functions?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template