- UID
- 49175
注册时间2008-5-1
阅读权限20
最后登录1970-1-1
以武会友
 
TA的每日心情 | 奋斗 2017-4-20 22:12 |
---|
签到天数: 1 天 [LV.1]初来乍到
|
发表于 2009-6-27 14:36:39
|
显示全部楼层
就是移动之后插入
#include<stdio.h>
#include<stdlib.h>
void Insert(char * substr,char * str,int index)
{
int les, j,i,subles;
les = strlen(str);
subles = strlen(substr);
if(index >= les)
memcpy(str+les,substr,subles+1);
else
{
//移动substr的字符串长度次
for(j=0;j<=subles-1;j++)
{
for(i=les+1+j;i>=index+j;i--)
*(str+i)= *(str+i-1);
}
//copy substr
memcpy(str+index,substr,subles);
}
}
main()
{
void *p = malloc(30);
memcpy(p,"ChinPYG",8);
Insert("suiyunonghen",p,4);//Insert("a",p,4);得ChinaPYG
puts(p);
} |
|