Reputation: 503
I have a char array,char contract[8];and assign the value to array,
and I want to print the value,so I use NSLog(@"%@",contract);
and build succeeded.but run incorrect.
Upvotes: 2
Views: 4654
Reputation: 376
If you know the size
NSLog(@"%.*s", 8, contract);
If contract is a NULL-terminated string
NSLog(@"%s", contract);
or just convert to NSString
NSLog(@"%@", [[[NSString alloc] initWithBytesNoCopy:contract length:contractLen encoding:NSASCIIStringEncoding freeWhenDone:NO] autorelease]);
Upvotes: 3
Reputation: 2962
for (Char *string in myArray) {
NSLog(@"%@", string);
}
Upvotes: 0
Reputation: 4174
Try
NSLog(@"%@",[NSString stringWithCString:contract encoding:NSUTF8StringEncoding]);
Basically, you need to make the C string an NSString object.
Upvotes: 7
Reputation: 26400
Please go through Format Specifiers. Try %c
instead of %@
. Hope this helps
Upvotes: -2