这段代码中的错误是什么?!!
提示:sp_to_dash()以下程序中的函数在其字符串参数中为每个空格打印一个破折号.也就是说,字符串"this is a test"将打印为"this-is-a-test".
#include <stdio.h>
void sp_to_dash( char *str);
int main(void)
{
sp_to_dash("this is a test");
return 0;
}
void sp_to_dash( char *str)
{
while(*str) {
if(*str==' ' ) *str = '-';
printf("%c", *str);
str++;
}
}
Run Code Online (Sandbox Code Playgroud)
字符串文字不可修改.这样改变:
int main(void)
{
char str[] = "this is a test";
sp_to_dash(str);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
171 次 |
| 最近记录: |