我目前正在编写一个函数,该函数应该将多个字符保存到 const char* 中,const char* 是该函数的参数。总体功能已给出,我无法更改参数。大致如下:
bool charChange(const char* array, uint32_t length)
{
for(uint32_t i = 0; i<length; i++){
int32_t nextChar = getChar(); //Get next character. Needs to be signed int, for other logic
array[i] = (char) nextChar;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
为了清楚起见,省略了一些逻辑,但这应该会突出问题。我尝试过各种黑魔法,但我不知道如何将字符传递给 const char 数组参数。说实话。这根本就没有道理。