/*功能:字符串截取*/
/*参数: str 传入字符串,StartPostion为开始位置下标,SubstringLength为截取长度*/
/*返回:截取的部分*/
char *SubString(char *str, int StartPostion, int SubstringLength)
{
int stringlen = 0;
int i = 0;
int x = 0;
char *tmp;
stringlen = strlen(str);
tmp = (char *)malloc(sizeof(char)*(SubstringLength + 1));
if ((StartPostion < 0) || (SubstringLength <= 0) || (stringlen == 0) || (StartPostion >= stringlen))
{
strcpy(tmp, "\0");
return tmp;
}
for (i = StartPostion; ((i < stringlen) && (x < SubstringLength)); i++)
{
tmp[x] = str[i];
x++;
}
tmp[x] = '\0';
return tmp;
}
C字符串截取函数
最新推荐文章于 2024-10-17 09:49:43 发布