2,586
社区成员
发帖
与我相关
我的任务
分享#include <iostream>
using namespace std;
#define MAX_COUNT 64
void InsertSpace(char* pszText, int nCount, int GAP)
{
if(NULL == pszText)
return ;
int nlen = strlen(pszText);
if(nlen <= 0 && ((nlen + nCount / GAP) >= (MAX_COUNT - 1)))
return ;
char* pEnd = pszText + nlen;
char* p = pszText;
int nIndex = 1;
while('\0' != *p++)
{
if(0 == nIndex++ % GAP)
{
while(pEnd > p)
{
*pEnd = *(pEnd-1);
pEnd--;
}
*p = ' ';
p++;
pEnd = pszText + strlen(pszText);
}
}
}
int main(int argc, char* argv[])
{
char buf[MAX_COUNT] = "abcdefghijk!";
InsertSpace(buf, MAX_COUNT-1, 3);
cout<<buf<<endl;
return 0;
}