更新时间:2022-12-28 16:50:50
从 input
中删除空格后,您还没有使用 nul-terminator (\0
>) 因为新的长度小于或等于原始字符串.
After removing the white spaces from the input
you have not terminated it with nul-terminator (\0
) because the new length is less than or equal to the original string.
只需在 for 循环结束时将其终止即可:
Just nul-terminate it at the of end your for loop:
char* deblank(char* input)
{
int i,j;
char *output=input;
for (i = 0, j = 0; i<strlen(input); i++,j++)
{
if (input[i]!=' ')
output[j]=input[i];
else
j--;
}
output[j]=0;
return output;
}