I usually use pointers in the following manner
char *ptr = malloc( sizeof(char) * 100 );
memset( ptr, 0, 100 ) ;
strncpy( ptr, "cat" , 100 - 1 );
But this time instead of using “cat”, I want to use it ASCII equivalent in hex.
cat = 0x63, 0x61, 0x74, 0x00
I tried
strncpy( ptr, "0x630x61" , 100 - 1 );
But it fails as expected.
What is the correct syntax?
Do I need to put a 0x00 too? For a moment lets forget about memset, now do I need to put a 0x00? Because in “cat” notation, a null is automatically placed.
Regards
\xXXis the syntax for inserting characters in hex format. so yours would be:You don’t need to put in a
\x00since having quotes automatically null-delimits the string.