使用C++对两个MAC地址去除特殊字符进行比较,比较是否为同一个数据
1条回答 默认 最新
- 赵4老师 2022-07-05 15:05关注
mac地址难道不是固定长度的字节数组,使用memcmp函数比较吗?
memcmp
Compare characters in two buffers.int memcmp( const void *buf1, const void *buf2, size_t count );
Routine Required Header Compatibility
memcmp <memory.h> or <string.h> ANSI, Win 95, Win NTFor additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail versionReturn Value
The return value indicates the relationship between the buffers.
Return Value Relationship of First count Bytes of buf1 and buf2
< 0 buf1 less than buf2
0 buf1 identical to buf20 buf1 greater than buf2
Parameters
buf1
First buffer
buf2
Second buffer
count
Number of characters
Remarks
The memcmp function compares the first count bytes of buf1 and buf2 and returns a value indicating their relationship.
Example
/* MEMCMP.C: This program uses memcmp to compare
- the strings named first and second. If the first
- 19 bytes of the strings are equal, the program
- considers the strings to be equal.
- /
#include <string.h>
#include <stdio.h>void main( void )
{
char first[] = "12345678901234567890";
char second[] = "12345678901234567891";
int result;printf( "Compare '%.19s' to '%.19s':\n", first, second );
result = memcmp( first, second, 19 );
if( result < 0 )
printf( "First is less than second.\n" );
else if( result == 0 )
printf( "First is equal to second.\n" );
else if( result > 0 )
printf( "First is greater than second.\n" );
printf( "Compare '%.20s' to '%.20s':\n", first, second );
result = memcmp( first, second, 20 );
if( result < 0 )
printf( "First is less than second.\n" );
else if( result == 0 )
printf( "First is equal to second.\n" );
else if( result > 0 )
printf( "First is greater than second.\n" );
}Output
Compare '1234567890123456789' to '1234567890123456789':
First is equal to second.
Compare '12345678901234567890' to '12345678901234567891':
First is less than second.Buffer Manipulation Routines
See Also _memccpy, memchr, memcpy, memset, strcmp, strncmp
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥100 任意维数的K均值聚类
- ¥15 stamps做sbas-insar,时序沉降图怎么画
- ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
- ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
- ¥15 关于#Java#的问题,如何解决?
- ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
- ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
- ¥15 cmd cl 0x000007b
- ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
- ¥500 火焰左右视图、视差(基于双目相机)