删除字符串中的空格(C language)

STATUS del_space(char* v_p_Str)
{	
	int len;
	char* pBkup = NULL;
	char* pSrcStr = NULL;
	char* pDesStr = NULL;
	char* pEnd = NULL;
	char  chFind = ' ';

	if(NULL == v_p_Str)
	{
		return ERROR;
	}
	len = strlen(v_p_Str);
	if(NULL == (pSrcStr = (char*)malloc(len + 1)))
	{
		return ERROR;
	}
	strcpy(pSrcStr, v_p_Str);
	pBkup = pSrcStr;
	pDesStr = pSrcStr;
	pEnd = pSrcStr + len;

	while(pSrcStr < pEnd)
	{
		if(chFind != *pSrcStr)
		{
			*pDesStr = *pSrcStr;
			pDesStr++;
		}
		pSrcStr++;
	}
	*pDesStr = '\0';
	strcpy(v_p_Str, pBkup);
	free(pBkup);

	return OK;
}

posted @ 2011-06-03 10:47  无忧一生  阅读(565)  评论(0编辑  收藏  举报