【发布时间】:2016-11-08 08:31:32
【问题描述】:
这是我在 Visual Studio 2008 中编写的代码。我在接收数组中获取数据并使用该数据,我正在准备响应它。但我收到错误“server.exe 中 0x0f6cf9c4 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000001。”每次代码运行时都在“strcat”函数处。
byte Receive[50];
unsigned char result[50];
int index = 0;
char *type;
char *s = "ff ff ff 1d 00 01 01 0b 00 01";
char *s1 = "03 00 98 ac 06 36 6f 92";
int i;
if (Receive[i] == 0x18)
{
if ((Receive[i+1] == 0x20) || (Receive[i+1] == 0x21) || (Receive[i+1] == 0x22) || (Receive[i+1] == 0x23) || (Receive[i+1] == 0x24) || (Receive[i+1] == 0x25))
{
if (Receive[i+2] == 0x00)
{
result[index] = Receive[i-4];`enter code here`
result[index+1] = Receive[i-3];
index = index+2;
type = "report";
}
}
}
}
index = 0;
if (type == "report")
{
strcat(s, result[index]);
strcat(s, result[index+1]);
strcat(s, s1);
strcat(s, array1[j]);
strcat(s, array1[j+1]);
strcat(s, array1[j+2]);
strcat(s, array1[j+3]);
strcat(s, array1[j+4]);
【问题讨论】:
-
与您的问题无关,但您不能使用
==来比较字符串。使用==,您只比较指针,而不是它们指向的内容,因此它永远不会是真的。使用strcmp比较字符串。 -
至于您的问题,首先在调试器中运行您的程序,以“在运行中”捕获崩溃。这样您就可以在代码中找到它发生的位置,并检查变量及其值以确保它们看起来不错。至少请编辑您的问题,告诉我们崩溃发生的位置以及所涉及变量的值。
标签: c