试图弄清楚下一个功能的确切目的是什么?
我知道它正在对字符串进行一些操作 - 获取 char 指针 - 命令,检查是否有空格或制表符空间......但最后我不明白这个函数在做什么?
void FixCommand(char* command)
{
char newCommand[MAX_COMMAND_SIZE + 1];
char* currChar = command;
int lastConfirmed = 0;
int inputIndex = 0;
while ((*currChar == ' ') || (*currChar == '\t'))
{
++currChar;
}
while (*currChar != 0)
{
if (*currChar != '\n')
{
newCommand[inputIndex] = *currChar;
++inputIndex;
if ((*currChar != ' ') && (*currChar != '\t'))
{
lastConfirmed = inputIndex;
}
}
++currChar;
}
newCommand[lastConfirmed] = 0;
strcpy(command, newCommand);
}