Created
June 17, 2014 17:54
-
-
Save iwilbert/d0efe909f1311c081bc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void replace(char[] line) { | |
int len; // original length; | |
int cnt = 0; // space count | |
for(len = 0; line[len] != '\0'; len++) | |
{ | |
if(line[len] == ' ') | |
cnt++; | |
} | |
int new_len = len + cnt*2; // length of new string | |
int k = new_len - 1; // starts from the end of new string | |
for(int i = len - 1; i >= 0; i--) // i starts from the end of original string | |
{ | |
if(line[i] == ' ') | |
{ | |
line[k] = '0'; | |
line[k-1] = '2'; | |
line[k-2] = '%'; | |
k -= 2; | |
} | |
else | |
line[k] = line[i]; | |
k--; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment