# include <stdio.h>
# include <string.h>
void str_replace(char * cp, int n, char * str)
{
int lenofstr;
int i;
char * tmp;
lenofstr = strlen(str);
//str3比str2短,往前移动
if(lenofstr < n)
{
tmp = cp+n;
while(*tmp)
{
*(tmp-(n-lenofstr)) = *tmp; //n-lenofstr是移动的距离
tmp++;
}
*(tmp-(n-lenofstr)) = *tmp; //move '\0'
}
else if(lenofstr > n)
//str3比str2长,往后移
{
tmp = cp;
while(*tmp) tmp++;
while(tmp>=cp+n)
{
*(tmp+(lenofstr-n)) = *tmp;
tmp--;
}
}
strncpy(cp,str,lenofstr);
}
int ma
统计一个英文文本文件中26个英文字母出现次数并按英文字母序输出统计结果,查找并替换此英文文本文件中某字符串。
于 2022-05-23 00:32:20 首次发布