问题描述及代码:
/*
*烟台大学计算机与控制工程学院
*作 者:马赛
*完成日期:2016年10月20日
问题描述:试编写算法实现将字符串S中所有值为c1的字符换成值为c2的字符
输入描述:无
程序输出:测试数据
*/
◇注:头文件以及功能函数的代码参见项目1 顺序串算法库。
☆main.cpp主函数代码
#include "sqstring.h"
void Trans(SqString &s, char c1, char c2)
{
int i;
for (i=0; i<s.length; i++)
if (s.data[i]==c1)
s.data[i]=c2;
}
int main()
{
SqString s;
StrAssign(s, "messages");
Trans(s, 'e', 'a');
DispStr(s);
return 0;
}
运行结果:
知识点总结:
运用了字符串的替换
学习心得:
对于字符串的操作有了新的认识。