我有过
int chop (char* input, unsigned int length)
{
for (int chopper = 0; chopper < = length; chopper++)
{
//how to pass 1byte this input to another function
//Will this for loop help?
}
}如何从该输入中提取一个字节的以供进一步处理?谢谢
发布于 2011-11-02 08:24:14
int chop (char* input, unsigned int length)
{
for (int chopper = 0; chopper < = length; chopper++)
{
doSomething(input[chopper]);
}
}发布于 2011-11-02 08:24:59
有什么问题吗
for (int chopper = 0; chopper < length; chopper++)
{
//how to pass 1byte this input to another function
//Will this for loop help?
unsigned char byte = input[chopper];
/// do whatever with the byte, and then move on to the next one
}注意,chopper < = length可能是错误的,您很可能想要chopper < length。
发布于 2011-11-02 08:27:38
您可以将指针视为只读数组,因此您可以像这样引用输入的单个字符:
input[chopper]您可能还应该将循环的结束条件更改为
chopper < length否则,您的循环的最后一次迭代将引用超出input大小的内存位置(从0开始)。
https://stackoverflow.com/questions/7974473
复制相似问题