I mean, I malloc a segment of memory, maybe 1k maybe 20bytes..
assume the pointer is pMem
How can I know the content pMem
refered is all Zero
or \0
. I know memcmp
but the second parameter should another memory address...
thanx
As others have already suggested you probably want memset or calloc.
But if you actually do want to check if a memory area is all zero, you can compare it with itself but shifted by one.
bool allZero = pMem[0] == '\0' && !memcmp(pMem, pMem + 1, length - 1);
where length is the number of bytes you want to be zero.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With