//1.题目把字符串中空格替换成 %20
//分析:
//循环遍历字符串,统计字符串个数
//根据空格个数延长字符串
//遍历字符串,替换空格符
void* repalceSpace(char *str ,int len)
{
int count = 0;
char* tmp = str;
while (*tmp!='\0')
{
if (*tmp == ' ')
count++;
tmp++;
}
int newsize = len + 2 * count;
str[newsize] = '\0';
char*end = str + len - 1;
char*new_end = str + newsize - 1;
while (end != new_end)
{
if (*end != ' ')
*new_end-- = *end;
else
{
*new_end-- = '0';
*new_end-- = '2';
*new_end-- = '%';
end--;
}
}
return str;
}
每日一题--空格替换
最新推荐文章于 2023-08-18 23:45:00 发布