描述: | 写出一个程序,接受三个参数,分别是一个字符串和两个字符,然后输出替换字符后的字符串。区分大小写。
例如1: 输入:ABCDEF,A,B 输出:BBCDEF
例如2: 输入:AABCDEF,A,C 输出:CCBCDEF
|
#include <stdlib.h>
#include <string.h>
#include "oj.h"
/*
功能:
输入:
输出:
返回:成功0,其它-1
*/
int ProcessString(char * strInput, char chSrc, char chDes, char * strOutput)
{
if (strInput == NULL || strOutput == NULL)
{
return -1;
}
int lens = strlen(strInput);
int count = 0;
while (*strInput != '\0')
{
if (*strInput == chSrc)
{
count++;
*strOutput++ = chDes;
}
else
{
*strOutput++ = *strInput;
}
strInput++;
}
*strOutput = '\0';
if (count == 0)
{
return -1;
}
return 0;
}