69,369
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <Windows.h>
void trim(char *pszStr){
int i, j, iLenght;
iLenght = strlen(pszStr);
char *pszTmp = (char*)malloc(iLenght + 1);
strncpy_s(pszTmp, iLenght + 1, pszStr, iLenght);
pszTmp[iLenght] = '\0';
i = 0;
j = strlen(pszTmp) - 1;
while (pszTmp[i] == ' ')
++i;
while (pszTmp[j] == ' ')
--j;
strncpy_s(pszStr, iLenght + 1, pszTmp + i, j - i + 1);
pszStr[j - i + 2] = '\0';
free(pszTmp);
pszTmp = NULL;
}
int _tmain(int argc, _TCHAR* argv[])
{
char szBegdate[11] = "2019-12-31";
trim(szBegdate);
return 0;
}