帮忙 看一下这是怎么了
#include <stdio.h>
#include <string.h>
#define STR_LENGTH 40
int main(void)
{
char str1[] = "to be or not to be";
char str2[] = ",tobe";
printf("\n%s\n", strcat(str1, str2));
return 0;
}
//执行时会弹出 该内存不能为 written.编译和连接均没提示错误。执行结果也正确。VC++6.0
[解决办法]
越界。
[解决办法]
strcat() does not perform bounds checking, and thus it risks overrunning str1 or str2. For a safer function that includes bounds checking, you can use strncat().
#include <string.h>
char *strncat( char *str1, const char *str2, size_t count );
[解决办法]
str1的长度不足,发生越界,新拼接的部分地址在其它程序中
两个解决办法
1.定义足够长的数组
char str1[50] = "to be or not to be";
2.使用更安全的strcat_s,越界会抛出异常