Is this short way for printing the string in hex is correct? If not, how it should be fixed?
uint8_t *m = string;
int c = sizeof(string);
while(c--){
printf("%02x ", *(m++));
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No “oneliner”, no. Besides, your code looks broken.
You can’t use
sizeoflike that, you probably meanstrlen().And you need to cast the character to an unsigned type to be safe.
So, something like this, perhaps:
Note that I don’t call
strlen(), since there’s no point in iterating over the string twice when once will do. 🙂