在 2 个字符的字符串 passCode 中用 _
替换空格的正确方法是什么?
最后它应该输入/输出:(a )
→ (a_)
。有没有办法使用 isspace 来做到这一点?
isspace(passCode[2]) == 0;
最佳答案
检查该字符是否为空格,如果是,则替换为_
。
例如:
#include <stdio.h>
#include <ctype.h>
int main ()
{
int i=0;
unsigned char str[]="a ";
while (str[i])
{
if (isspace(str[i]))
str[i]='_';
i++;
}
printf("%s\n",str);
return 0;
}
关于c - C语言中的空格替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26052675/