Skip to content

Instantly share code, notes, and snippets.

@songpu2015617
Created April 6, 2015 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save songpu2015617/7db42adbff6c83f12b3b to your computer and use it in GitHub Desktop.
Save songpu2015617/7db42adbff6c83f12b3b to your computer and use it in GitHub Desktop.
CC150 1.4
#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