Created
July 15, 2016 08:09
-
-
Save Mattosx/f2f77daf4e7c989ce4e93708310f5947 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
string replaceNullStr(const char* input){ | |
size_t srcLen = strlen(input); | |
const char* p = input; | |
int nullStr = 0; | |
while (*p != '\0') { | |
if (*p == ' ') { | |
++nullStr; | |
} | |
++p; | |
} | |
size_t outLen = srcLen + 2 * nullStr + 1; | |
char outBuff[outLen]; | |
p = input; | |
char* outBuff2 = outBuff; | |
while (*p != '\0') { | |
if (*p == ' ') { | |
strcpy(outBuff2, "%20"); | |
outBuff2 += 3; | |
++p; | |
}else{ | |
*outBuff2 = *p; | |
++p; | |
++outBuff2; | |
} | |
} | |
return outBuff; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment