标签:fun ++ str 指针 strcpy abc 数组 函数 拷贝
写一个函数,将字符串中空格替换为%20。样例:"abc defgx yz"替换为"abc%20defgx%20yz"。Fun(char str)
{
char p = str;
char arr[20];
while (p != ‘\0‘)
{
if (p == ‘ ‘)
{
strcpy(arr, p + 1);
p = ‘%‘;
(p + 1) = ‘2‘;
*(p + 2) = ‘0‘;
strcpy(p + 3, arr);
p = p + 3;
continue;
}
p++;
}
}
标签:fun ++ str 指针 strcpy abc 数组 函数 拷贝
原文地址:https://blog.51cto.com/14239789/2429505