All I need this for is strcpy().
I want to see whether the first three bytes of a buffer(byte array) are “JMX” as string.
This is what I did so far:
char * ddj;
strcpy( ddj, buffer ); //buffer is BYTE[]
if ( strcmp( "JMX", ddj ) == 0 ) //check first three chars are "JMX"
{
buffer += 20; //increase the index with 20
size -= 20; //int
}
I get exception at strcmp() line. What is the problem?
I wish I was writing this in C# 🙁
Tho things go wrong here:
ddjdoes not point to any actual memory. Hence the copy will have undefined behaviorThis is what you can do:
This uses strncmp instead of strcmp, thus ensuring that no more than three bytes are compared. If
buffercan contain less than three bytes, you should do something like: