memcmp 函数的使用
memcmp 函数的定义
int memcmp ( const void * ptr1, const void * ptr2, size_t num );
- ⽐较从ptr1和ptr2指针指向的位置开始,向后的num个字节
- 返回值如下:
标签:printf,函数,int,memcmp,使用,buffer1,buffer2 From: https://blog.csdn.net/weixin_52978505/article/details/137152940memcmp 函数的使用
#include <stdio.h> #include <string.h> 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; }