字符替换:
编写程序,用指定的字符替换字符串中相应的字符(如果存在字符的大写形式,则替换为对应的大写形式
),并统计替换字符的个数。
输入:
分两行输入,第一行为要查找的字符和替换的内容,第二行为目标字符串(长度不超过255)
请从ex4.txt中读取测试数据。
输出:替换后的结果以及替换的字符数
#include<stdio.h>
int main()
{
char c1,c2,*p1,*p2;
char s[255];
freopen("ex4.txt","r",stdin);
while(scanf("%c %c",&c1,&c2)!=EOF)
{
int count=0,*t;
p1=c1; p2=c2;
getchar();
gets(s);
char *p=s;
while(*p)
{
if(toupper(*p)==toupper(c1))
{
if(isupper(*p)) *p;
t=p1;
p1=p2;
t=p2;
count++;
}
p++;
}