数组处理函数(获取字符数组中一定长度的字符,修改字符数组的某个字符)
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;
}
/**
*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;
}
相关文章推荐
- C 语言 实现 字符串 分割 函数(返回"二维字符数组",及分割后的字符数组的长度)
- 随机生成一个 10 个元素的数组,找到 x 的倍数,并将其值修改成 0.(注意:修改数值使用回掉函数处理)
- PHP截取字符串,获取长度,获取字符位置的函数
- 关于sizeof在调用函数中获取被调函数数组长度的思考
- 字符数组函数,连接strcat 复制函数strcpy 比较函数strcmp 长度函数 strlen
- 通过PHP current函数获取未知字符键名数组第一个元素的值
- 通过PHP current()函数获取未知字符键名数组第一个元素的值
- 根据服务器端返回的字符数组,展示字符串标签,需要涉及字符串长度处理以及字符串换行,字符串不够一行自动跳到第二行的逻辑
- PHP截取字符串,获取长度,获取字符位置的函数 中文字符截取
- 字符数组及字符串的处理函数
- PHP截取字符串,获取长度,获取字符位置的函数
- 字符数组,字符串,处理字符串的函数,周小结
- 传递到函数 中的数组如何获取长度
- 通过PHP current函数获取未知字符键名数组第一个元素的值
- 字符数组的定义、初始化及引用以及一些常用的字符串处理函数
- PHP获取数组长度的方法 函数参数的比较
- 修改程序清单7.7中的3个数组处理函数,使之使用两个指针参数来表示区间.
- 通过PHP current函数获取未知字符键名数组第一个元素的值
- C\C++常用字符串\字符数组处理函数汇总
- string常量及字符数组的长度函数、赋值、拼接、附加