您的位置:首页 > 其它

数组处理函数(获取字符数组中一定长度的字符,修改字符数组的某个字符)

2014-04-17 19:39 267 查看
希望大家仔细看一下 希望能够找到一些漏洞,能让这些函数更加完善一些

/**
*retval:
-1:length input error
0:buf input NULL
1:get date success
*function:
Get a part of words from array,and save to outBuf
*parameter:
start:position of start
length: length that you want to get
inBuf:word from
outBuf:word saving to
*/
static const int readFromBuf(const unsigned int start,unsigned int length,const char* inBuf, char* const outBuf)
{
if(start > strlen(inBuf) || start <= 0 || length > (strlen(inBuf) - start))
{
return -1;
}
if(NULL == inBuf || NULL == outBuf)
{
return 0;
}
char *inTemp = NULL;
char *outTemp = NULL;

inTemp = (char*)(inBuf + start - 1);
outTemp = outBuf;

while(length--)
{
*outTemp++ = *inTemp++;
}
return 1;
}

/**
*retval:
-1:position too long
0:inBuf is NULL
1:write success
*/
static const int writeByteToBuf(const unsigned int position,char *inBuf,char byte)
{
if(position > strlen(inBuf) || 0 == position)
{
return -1;
}
if(NULL == inBuf)
{
return 0;
}
*(inBuf+position-1) = byte;

return 1;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐