数组读取
u8 ledduan[]={0x3C,0x52,0xA5,0x93,0x93,0xA5,0x52,0x3C,0x3C,0x52,0xA5,0x93,0x93,0xA5,0x52,0x3C};c语言里怎么实现类似于python中切片的操作?
比如说我想读取ledduan到ledduan这几个数,应该要怎么操作?
for 循环,一个字节一个字节的读取 #include <stdio.h>
int main(void)
{
unsigned char ledduan[]={0x3C,0x52,0xA5,0x93,0x93,0xA5,0x52,0x3C,0x3C,0x52,0xA5,0x93,0x93,0xA5,0x52,0x3C} ;
unsigned char d ;
int i ;
for(i = 2 ; i < 9 ; i ++) d = ledduan ;
for(i = 0 ; i < 7 ; i ++) printf("d[%d] = 0x%02X\n" , i , d) ;
}
编译、运行实况:
D:\00.Excise\C>g++ -o x x.c
D:\00.Excise\C>x
d = 0xA5
d = 0x93
d = 0x93
d = 0xA5
d = 0x52
d = 0x3C
d = 0x3C
D:\00.Excise\C>
页:
[1]