1、题目要求:
去除字符串前后的空格字符。
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
int getnewStr(char* src, char* dst)
{
int ret = 0;
char* p1 = src;
int i = 0;
int j = strlen(p1) - 1;
int len = 0;
while (isspace(p1[i]) && *(p1 + i) != '\0')
{
i++;
}
while (isspace(p1[j]) && p1[j] != '\0')
{
j--;
}
len = j - i + 1;
strncpy(dst, p1 + i, len);
return ret;
}
int main()
{
char buf[] = " abcd ";
char str[16] = { 0 };
getnewStr(buf, str);
printf("str=%s\n", str);
system("pause");
return 0;
}