第1个回答 2019-09-18
我有一点建议,能使用库函数的,尽量使用库函数。
keil
c51中的<string.h>中,有一系列的关于内存拷贝方面的函数:
extern
void
*memcpy
(void
*s1,
void
*s2,
int
n);
extern
void
*memmove
(void
*s1,
void
*s2,
int
n);
//s1:dest
s2:src
n:len
例如使用其中的memmove来实现你要的功能。假设你的x,y是基0的(也就是说0表示第1个字符),则
#include
"string.h"
typedef
unsigned
char=uchar;
uchar
buf[30];
uchar
a[30];
memmove(a,buf+x,y-x+1);
说明一下,memcpy和memmove的区别就是:memmove能更好地完成两个内存区域有重叠的情况!