首先strset(或者更确切地说_strset)是 Windows 特定的功能,它不存在于任何其他系统中。通过阅读它的文档,它应该很容易实现。
但是您还有一个次要问题,因为您将未初始化的数组传递给函数,该函数需要一个指向以空字符结尾的字符串的第一个字符的指针。这可能导致未定义的行为。
这两个问题的解决方案是直接初始化数组:
char hey[100] = { 0 }; // Initialize all of the array to zero
如果您的目标是将现有的以空字符结尾的字符串“重置”为全零,请使用以下memset函数:
char hey[100];
// ...
// Code that initializes hey, so it becomes a null-terminated string
// ...
memset(hey, 0, sizeof hey); // Set all of the array to zero
或者,如果您想_strset具体模拟以下行为:
memset(hey, 0, strlen(hey)); // Set all of the string (but not including
// the null-terminator) to zero