#define _CRT_SECURE_NO_WARNINGS 1


#include <stdio.h>

#include <assert.h>


void repace_black(char *str)

{

assert(str);

char *pstr = str;

int black = 0;

int len = 0;

int newlen = 0;

while (*str)

{

if (*str == ' ')

black++;

len++;

str++;

}

newlen = len + black * 2;

char *newptr = pstr + newlen - 1;

char *oldptr = pstr + len - 1;

while (oldptr < newptr)

{

if (*oldptr == ' ')

{

*newptr-- = '0';

*newptr-- = '2';

*newptr-- = '%';

}

else

{

*newptr-- = *oldptr;

}

oldptr--;

}

}

int main()

{

char str[20] = "we are happy.";

repace_black(str);

printf("%s\n", str);

system("pause");

return 0;

}