bilibiliclass53_C语言_memcmp 内存比较函数

memcmp
内存比较函数

库函数声明
int memcmp ( const void * ptr1,
const void * ptr2,
size_t num );
比较从ptr1和ptr2指针开始的num个字节
简单例子

#include 
#include 

int main ()
{
char buffer1[] = “DWgaOtP12df0”;
char buffer2[] = “DWGAOTP12DF0”;

int n;

n=memcmp ( buffer1, buffer2, sizeof(buffer1) );

if (n>0) printf ("’%s’ is greater than ‘%s’.\n",buffer1,buffer2);
else if (n<0) printf ("’%s’ is less than ‘%s’.\n",buffer1,buffer2);
else printf ("’%s’ is the same as ‘%s’.\n",buffer1,buffer2);

return 0;
}
//结果:’DWgaOtP12df0’ is greater than ‘DWGAOTP12DF0’.

你可能感兴趣的:(C语言_哔哩哔哩课堂笔记)