I am trying to write to NSoutputStream as below:
+(void)write:(char[])data
{
int size=(sizeof data) / (sizeof data[0]);
[outputStream write:(const uint8_t *)data maxLength:size];
}
is this right? Also how can I read NSInputStream into an char[].
No, it isn't right. Arrays are not pointers , hence the sizeof()
operator here doesn't do what you think it does. Use an explicit length
argument.
(Furthermore, sizeof(char)
is always 1, so you don't have to spell it out.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.