Created
April 6, 2015 02:20
-
-
Save songpu2015617/7db42adbff6c83f12b3b to your computer and use it in GitHub Desktop.
CC150 1.4
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
#include <iostream> | |
#include <cstring> | |
using namespace std; | |
char* replace1(char *c){ | |
if(c == NULL) return NULL; | |
int len = strlen(c); | |
if(len == 0) return NULL; | |
int cnt = 0; | |
for(int i=0; i<len; ++i) | |
{ | |
if(c[i] == ' ') | |
++cnt; | |
} | |
char *cc = new char[len+2*cnt+1]; | |
int p = 0; | |
for(int i=0; i<len; ++i) | |
{ | |
if(c[i] == ' ') | |
{ | |
cc[p] = '%'; | |
cc[p+1] = '2'; | |
cc[p+2] = '0'; | |
p += 3; | |
} | |
else | |
{ | |
cc[p] = c[i]; | |
++p; | |
} | |
} | |
cc[p] = '\0'; | |
return cc; | |
} | |
int main(){ | |
const int len = 100; | |
char c[len] = ""; | |
cout<<replace1(c)<<endl; | |
replace2(c); | |
cout<<c<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment