[英]I get the error message:Expression: (L “String is not null terminated” & & 0)
When I run my Program,I get the error message.I don't konw how to correct it.May I get a help? 当我运行我的程序时,我收到错误消息。我不知道如何纠正它。我可以寻求帮助吗?
char dir[1024]="C:\\Users\\UserName\Desktop\\new folder\\Pauli\\T3";
void check_dir(char *dir)
{
int i;
i = 0;
while (dir[i] != '\0') {
if (dir[i] == '/')
dir[i] = '\\';
i++;
}
strcat_s(dir, sizeof(dir),"\\");
}
sizeof(dir)
doesn't do what you obviously expect here. sizeof(dir)
并没有明显满足您的要求。 As dir
is a char *
inside your function, it just gives you the size of the pointer (*). 由于
dir
是函数内部的char *
,因此它只为您提供指针(*)的大小。 Your only option is to pass the size of the array to your check_dir()
function, too: 您唯一的选择就是也将数组的大小传递给您的
check_dir()
函数:
void check_dir(char *dir, size_t bufsize)
{
[...]
strcat_s(dir, bufsize, "\\");
}
(*) In the scope where dir is declared char dir[1024]
, sizeof(dir)
will give you the expected result. (*)在dir声明为
char dir[1024]
的范围内, sizeof(dir)
将为您提供预期的结果。
edit: On a side note, check_dir()
is a misnomer here, as it doesn't check anything but tries to normalize the string to be a windows path with backslashes. 编辑:
check_dir()
一句, check_dir()
在这里是一个误称,因为它不检查任何内容,而是尝试将字符串标准化为带有反斜杠的Windows路径。 Call it eg win32_normalize_path()
or something like that. win32_normalize_path()
或类似的名称。 Something called check_<foo>()
should return something (eg int
) containing the result of the check. 称为
check_<foo>()
东西应该返回包含检查结果的东西(例如int
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.