Write a function, the string in the spaces with% 20.

Write a function, the string in the spaces with% 20. Sample: "abc defgx yz" is replaced with "abc% 20defgx% 20yz".
This question is a simple replacement character string and replace problem, with the pointer to the character, always need to be saved directly to a string of spaces array, and then replace the space was 20% just before the copy copy of the string to the back 20% of the code is as follows:


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++;
}
}

Guess you like

Origin blog.51cto.com/14239789/2429505