03一道编程题。/* 输入1个字符,用该字符替换原始字符串中的空格后,输出字符串 */

来源:百度知道 编辑:UC知道 时间:2024/06/06 13:11:35
#include <stdio.h>
#include <conio.h>
#include <string.h>
void fun(char s[],char c)
{

}
main()
{
static char str[]="you and me ";
char ch;
clrscr() ;
printf("原始字符串:%s\n", str);
printf("输入一个字符:");
scanf("%c",&ch);
fun(str,ch);
printf("str[]=%s\n",str);
NONO();
}
谢谢你的回答!现在运行说if(s[x]==' ') s[x]=ch;的最后的ch;的;有错误。请您再帮忙看下;您最后的/*NONO();*/
getch();
} 和我给的不一样啊?我这题别的地方不能改,只能在上面那{}中添东西;还有就是您说函数fun中第二个参数少了一个h ,是什么意思?

#include <stdio.h>
#include <conio.h>
#include <string.h>
void fun(char s[],char c)
{
int x;
for(x=0;x<=strlen(s);x++)
if(s[x]==' ') s[x]=c; /*单引号''中间要有空格*/
}
main()
{
static char str[]="you and me ";
char ch;
clrscr() ;
printf("原始字符串:%s\n", str);
printf("输入一个字符:");
scanf("%c",&ch);
fun(str,ch);
printf("str[]=%s\n",str);
/*NONO();*/
getch();
}

win xp + win tc 编译通过