简体   繁体   English

为函数分配的参数太多了?

[英]Too many arguments are assigned to the function?

I define a variable 我定义了一个变量

wchar_t path[256];

Then I try to get the strlen() of this variable 然后我尝试获取此变量的strlen()

strlen(path);

Error is strlen() too many arguments? 错误是strlen()参数太多了吗?

I don't understand, I am only passing 1 argument to strlen() and path is simple a char of size WORD that can span up to 256 characters? 我不明白,我只向strlen()传递一个参数,而path是简单的一个大小为WORD的字符,最多可以包含256个字符?

What is the issue here? 这是什么问题? How can I circumvent it? 我怎么能绕过它呢?

SOLVED! 解决了!

To get around this I simply type casted the sPath wchar_t as a (const BYTE *) therefore it allowed me to read in ASCII which told the strlen() function to stop counting when it hits zero. 为了解决这个问题,我只需输入sPath wchar_t作为(const BYTE *)因此它允许我读取ASCII,它告诉strlen()函数在它达到零时停止计数。 Works now. 现在工作。

您可以使用wcslen函数(在头文件<wchar.h>定义),它将const wchar_t *str作为参数,而strlen需要一个const char *str

strlen() looks for a '\\0' in the supplied string. strlen()在提供的字符串中查找'\\ 0'。 Which is a null terminating string. 这是一个空终止字符串。 If you pass it an uninitialized string it may look forever because who knows whats in the memory before you put something there. 如果你传递一个未初始化的字符串,它可能看起来永远,因为谁知道你在那里放东西之前记忆中的什么。 Which to continue means strlen() looks till it finds '\\0' which if there is no '\\0' it won't stop it'll read all the memory it can, should produce a endless loop. 哪个继续意味着strlen()看​​起来直到它找到'\\ 0',如果没有'\\ 0'它将不会停止它将读取它可以的所有内存,应该产生无限循环。

Try putting: 尝试放:

char path[256] = {"test"};

Pass that, it auto null terminates in that case. 通过它,在这种情况下auto auto null终止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM