#include <stdio.h>
#include <stdlib.h>
void replace_blank(char *p)
{
int len = 0;
int newlen = 0;
int blank_count = 0;
char *pstr = p;
while (*pstr)
{
if (*pstr == ' ')
blank_count++;
len++;
pstr++;
}
newlen = len + 2 * blank_count;
while (len < newlen)
{
if (p[len] == ' ')
{
p[newlen--] = '0';
p[newlen--] = '2';
p[newlen--] = '%';
}
else
{
p[newlen--] = p[len];
}
len--;
}
}
int main()
{
char p[20] = "we are happy.";
replace_blank(p);
printf("%s\n", p);
system("pause");
return 0;
}