#define _CRT_SECURE_NO_WARNINGS
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
/*
有一个字符串开头或结尾含有n个空格(" abcdefgddddd "),欲去掉前后中空格,返回一个新字符串;
要求1:请自己定义一个接口(函数),并实现功能;
要求2;编写测试用例;
int trimspace(char *inbuf,char *outbuf)
*/
char str_cpy(char *p, char *p1)
{
int ret = 0;
if (p == NULL || p1 == NULL) //判断传过来的地址是否为空;
{
ret=-1;
printf("func p == NULL || p1 == NULL err %d",ret);
return ret = -1;
}
char *str1 = NULL;
char *str2 = NULL;
str1 = p;
str2 = p1;
int i = 0;
int j = 0;
while (str2[i] != '\0')
{
if (str2[i] != ' ')
{
str1[j] = str2[i];
j++;
i++;
}
else
{
i++;
}
}
str1[j] = '\0';
return ret;
}
void main()
{
char* str1 = " I _ MISS _YOU _XU _HUAN _I _AM _CRAZYSPOPCORN "; //定义字符串
char str2[400]; //定义另外一个字符数组,当做输出;
str_cpy(str2, str1);
printf("%s", str2);
system("pause");
}
有一个字符串开头或结尾含有n个空格( a b c d ),欲去掉前后中空格,返回一个新字符串
最新推荐文章于 2020-01-16 09:15:01 发布