char* DivideStr(char* display_str)
{
int length = 0;
int k = 0;
int i = 0;
int len = 0;
length = strlen(display_str)+1;
char* tempStr = new char[length+length/5];
memset(tempStr,0,length+length/5);
while(display_str[k]!='\0')
{
if(display_str[k] <= 122&&display_str[k] >= 32)
{
tempStr[i] = display_str[k];
len++;
i++;
k++;
}
else
{
tempStr[i] = display_str[k];
if(display_str[k+1]!='\0')//如果是汉字就需要双字节计算
{
tempStr[i+1] = display_str[k+1];
}
len++;
i+=2;
k+=2;
}
if(len%5 == 0)
{
tempStr[i++] = '$';
}
}
return tempStr;
}
int main()
{
char* str = "一个抽象类tyu吧453u是么";
printf("%s\n",DivideStr(str));
return 0;
}