Replace all spaces in a string with “%20″ in c-style string
Problem Write a C program that will replace all spaces with ‘%20′
Example
Input: “Mr John Smith "
Output: “Mr%20John%20Smith
Solution The algorithm is as follows:
Count the number of spaces during the first scan of the string. Parse the string again from the end and for each character:
If a space is encountered, store “%20”.
Else, store the character as it is in the newly shifted location.
[Read More]