如何找到用C无符号的char *的长度 [英] How to find the length of unsigned char* in C

查看:776
本文介绍了如何找到用C无符号的char *的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量

unsigned char* data = MyFunction();

如何查找数据的长度?

how to find the length of data?

推荐答案

您必须从的MyFunction 传递数据的长度了。此外,还要确保你知道谁分配内存和谁有权释放它。这有各种图案。很多时候我看到:

You will have to pass the length of the data back from MyFunction. Also, make sure you know who allocates the memory and who has to deallocate it. There are various patterns for this. Quite often I have seen:

int MyFunction(unsigned char* data, size_t* datalen)

您然后分配数据和通DATALEN,结果(INT),那么应该指出,如果你的缓冲区(数据)是足够长的时间...

You then allocate data and pass datalen in. The result (int) should then indicate if your buffer (data) was long enough...

这篇关于如何找到用C无符号的char *的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆