博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
串指出位置的插入
阅读量:4227 次
发布时间:2019-05-26

本文共 1093 字,大约阅读时间需要 3 分钟。

/*******************************************
*
*insert a character into a existed string
*
*******************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char * insert(char * pDstString, char * pSrcString, int iPosInString)
{
if (!pDstString)
{
printf("The destination string is not existed!");
return NULL;
}
int iLengthOfDstString = strlen(pDstString);
if (iPosInString > iLengthOfDstString + 1 || iPosInString < 0)
{
printf("The specified position in the string is not valid!");
return NULL;
}
int iLengthOfSrcString = strlen(pSrcString);
char * pResultString = NULL;
pResultString = (char *)malloc((iLengthOfDstString + iLengthOfSrcString + 1) * sizeof(char));
if (pResultString == NULL)
{
return NULL;
}
strcpy(pResultString, pDstString);
strcpy(pResultString + iPosInString, pSrcString);
strcpy(pResultString + iLengthOfSrcString, pDstString + iPosInString);
return pResultString;
}
int main()
{
char * pDst = "abc";
char * pSrc = "okokok";
char * pResult = NULL;
pResult = insert(pDst, pSrc, 1);
printf("%s", pResult);
free(pResult);
return 0;

转载地址:http://pxdqi.baihongyu.com/

你可能感兴趣的文章
CPU占用高,导致请求超时的故障排查
查看>>
SHELL基础 -1
查看>>
SHELL基础 -2
查看>>
Nginx
查看>>
Memcached,session共享
查看>>
Tomcat,varnish
查看>>
SVN, 制作RPM包
查看>>
HTML 标签说明
查看>>
CSS 基本语法
查看>>
CSS 尺寸、样式属性
查看>>
Bootstrap
查看>>
Django 项目管理
查看>>
Django 模板与表单
查看>>
多线程,多进程
查看>>
shell脚本 注意事项
查看>>
Premetheus
查看>>
TCP连接的状态详解以及故障排查
查看>>
Nginx
查看>>
Nginx 常见异常
查看>>
Linux服务器_安全隐患
查看>>