一个字符串中的某个字符,替换为另一个字符
简单信息加密,编写一个函数实现加密功能,完成对一个字符串中的某个字符,替换为另一个字符。字符串、要替换的字符及替换后字符,由数据输入给出。主函数中完成替换后字符串的输出。Input
输入数据只有多组,每组为二行,第一行数值n(1=<n<=5),然后是另起一行,分别为n行字符串(每行不超过100个字符)。每个字符串单独一行,第一个字符为查找字符,第二个字符为替换字符,两个字符之间用一个空格分隔,然后为一个空格分开的字符串。格式见输入示例。
Output
输出替换后的字符串,每组数据单独一行输出。见输出示例。
Sample Input
2
I i ThIs Is a C Program
T t Now,I am Testing!
Sample Output
This is a C program
Now,I am testing!
程序代码:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int fun(char a[101],char xx,char yy)
{
int j;
for(j=0;j<strlen(a);j++)
{
if(a[j]=='xx')
a[j]='yy';
}
return a;
}
void fun2(char a[101],char xx,char yy)
{
int j;
char b[101];
for(j=0;j<strlen(a);j++)
{
if(a[j]=='xx')
b[j]='yy';
else
b[j]=a[j];
}
// return b;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int i=0;
for(;i<n;i++)
{
char c[101],x,y;
scanf("%c",&x);
scanf(" %c",&y);
gets(c);
fun2(c,x,y);
puts(c);
}
}
return 0;
}
哪里写的不对

fun 和fun2 哪个对?









