char* replaceSpace(char* s){
int count = 0;
int len = strlen(s);
for (int i = 0; i < len; i++)
{
if (s[i] == ’ ')
{
count++;
}
}
int newLen = len + count * 2;
char* r = malloc(sizeof(char) * newLen + 1);
for (int i = len - 1, j = newLen - 1; i >= 0; i–, j–)
{
if (s[i] != ’ ')
{
r[j] = s[i];
}
else
{
r[j–] = ‘0’;
r[j–] = ‘2’;
r[j] = ‘%’;
}
}
r[newLen] = ‘\0’;
return r;
}
替换空格(C语言)
最新推荐文章于 2024-06-20 12:36:33 发布