how to print out UInt16 pointer to NSLog
I am just trying to print out UInt16 pointer to my log, So i can see its contence... however thus far am not having any sucsess, dose anyone know how to do this, I am thinking its the format specifier but because I dont have alot of experience with this type of thing I just dont know. the warning I am getting is "initialization discards qualifiers from pointer target type"
//....
[nissanCode seekToFileOffset: 2];
dataBuffer = [nissanCode readDataOfLength:SETSIZE];
UInt16 *ans = dataBuffer.bytes;
UInt16 a = *ans;
NSLog (@"Data = %@", a);
//....
//Revised code that clears the warning and prints data out fine. thanks f开发者_StackOverflow社区or the help guys.
//....
[nissanCode seekToFileOffset: 2];
dataBuffer = [nissanCode readDataOfLength:SETSIZE];
const UInt16 *ans = dataBuffer.bytes;
NSLog (@"Data = %d", a);
//....
try using for int's
NSLog(@"Data = %d", a);
or for your UInt16's (thanks to @bshirley for the list of format specifiers below)
NSLog(@"Data = %hu", a);
Are you trying to print the address or the value? From how your code is setup you should be using %d
, but for the pointer you would use NSLog("%p", ans);
. The %@
format is for objects only.
精彩评论