memcpy strncmp 都可以
|
|
取buffer前面的字符出来进行比对?
|
|
一般控制数据协议,读取某一个字节就行了
|
|
memcmp 上面打错了
|
|
你这个EB905716165790EB表示是ascii码?还是16进制的字节?不管是哪种情况,都不能用strcmp,用memcmp就可以了。
|
|
10分 |
#include<iostream> #include<stdio.h> using std::cout; using std::endl; int main(int argc, char **argv) { char tmp[3][1024] = { "EB905716165790EBsfsfsfasdaf", "xsffEB905716165790EBdogfd.gf;gdk", "\0" }; for( int i = 0; i < 3; i++ ) { if( 0 != strncmp(tmp[i], "EB905716165790EB", 16) ) // 比较前16个字符 { // 如果没什么强制要求和需求必须使用memset,你可以用tmp[0] = ""\0""让字符串为空串 //memset(tmp[i], 0, sizeof(tmp[i]) ); tmp[i][0] = ""\0""; } cout << tmp[i] << endl; } } |
10分 |
memcmp
Compare characters in two buffers. int memcmp( const void *buf1, const void *buf2, size_t count ); Routine Required Header Compatibility For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version Return Value The return value indicates the relationship between the buffers. Return Value Relationship of First count Bytes of buf1 and 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 #include <string.h> void main( void ) printf( “Compare “”%.19s”” to “”%.19s””:\n”, first, second ); Output Compare “”1234567890123456789″” to “”1234567890123456789″”: Buffer Manipulation Routines See Also _memccpy, memchr, memcpy, memset, strcmp, strncmp |