uint8_t *var;
var=//something;
现在我想遍历此var的每个元素 这该怎么做 请帮忙
答案 0 :(得分:4)
像普通C一样制作循环。uint8_t *var
只是一个C数组。
for (uint8_t i = 0; i < ARRAY_LENGTH; ++i) {
var[i] = ...; // Do whatever you want
}
例如
uint8_t *v = (uint8_t *)malloc(5 * sizeof(uint8_t));
for (uint8_t i = 0; i < 5; ++i) {
v[i] = i;
}
for (uint8_t i = 0; i < 5; ++i) {
NSLog(@"%d\n", v[i]);
}
free(v);
请注意,uint8_t
与unsigned char
相同:
#ifndef _UINT8_T
#define _UINT8_T
typedef unsigned char uint8_t;
#endif /*_UINT8_T */