将空格替换成%20
example: we are happy , 修改成 we%20are%20happy
int main()
{
char* p = (char*)malloc(sizeof(char) * 100);
//char p[100];
gets(p);
//scanf("%s",p);
assert(p);
int l = strlen(p) - 1;
int tmp = l;
int lt = l;
int max = 0;
while (tmp)
{
if (p[tmp] == ' ')
{
l += 2;
lt = l;
max = lt;
while (lt > tmp)
{
p[lt] = p[lt-2];
lt--;
}
p[tmp] = '%';
p[tmp + 1] = '2';
p[tmp + 2] = '0';
}
tmp--;
}
p[max + 1] = '\0';
printf("%s\n", p);
return 0;
}
完整代码已放入github中: