阅读:1556回复:1
麻烦帮看看函数调用中这两个数组什么地方出了问题?
麻烦帮看看函数调用中这两个数组什么地方出了问题?vc6.0下编译
我这个程序为什么aa数组和bb数组中的数据不一样,在调用sendstring()函数的时候输出bb数组的时候aa数组中的内容也跟在后面了? 谢谢.... #include <windows.h> #include <iostream.h> #include <stdio.h> void strcopy(unsigned char *destr,unsigned char *soustr) { int e = 0; for(e=0; soustr[e]!=0xfa&&soustr[e]!='\0'; e++) destr[e] = soustr[e]; destr[e] = '\0'; } void sendstring(unsigned char *str) { unsigned char kd[20]; for(int ecount=0; ecount<20; ecount++) kd[ecount] = '\0'; //cout << kd << endl; strcopy(kd,str); for(unsigned int i=0; i<strlen((const char *)kd); i++) printf("%x ",kd); //cout << kd <<" " << endl; } void sendfirst(void) { unsigned char aa[5] = {0xaa,0xe0,0x45,0x01,0x76}; unsigned char bb[6] = {0xaa,0x10,0x45,0x02,0x7f,0x03}; unsigned char e[20]; int count = 0; sendstring(aa); for(count=0; count<20; count++) e[count] = '\0'; sendstring(bb); void main(void) { sendfirst(); } 程序运行的结果是: aa e0 45 1 76 cc cc cc 89 ff 12 aa 10 45 2 7f 3 cc cc aa e0 45 1 76 cc cc cc 89 ff 12 |
|
沙发#
发布于:2007-03-21 09:32
因为AA BB两个数组没有以'\0'或者0xfa结尾,strcopy的时候数组越界了
|
|