Now I use the follow code to init buf[], but I wanna pass a string to buf[], then how can I convert string to buf[]? Thanks!
UInt8 buf[] = "hello world";
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.
I’ll assume that, by “string”, you meant an
NSString *.The length of a string is unknown at compile-time, so you can’t define a
UInt8 buf[]to contain the value. You have to either pre-specify the length (e.g.,UInt8 buf[100]), or copy the string into heap memory and refer to it with aUInt8 *buf.For the first approach:
For the second, this is one way to do it: