去除字符串前后空格,挖出新字符串

#include<stdio.h>
void trimspae(char *str,char *newstr)
{
char*p=str;
int i,j,ncount;
i=0;
j=strlen(p)-1;
if(str==NULL||newstr==NULL)
{
printf("func trimspace() \n");
return -1;
}

while(isspace(p[i])&&p[i]!=0)
{
i++;
}
while(isspace(p[j])&&p[j]!=0)
{
j--;
}
ncount=j-i+1;
strncpy(newstr,str+i,ncount);
}

void main()
{
char *str=" qabfe ";
char buf[64]={0};
trimspae(str,buf);
printf("buf:%s",buf);
}

posted @ 2018-03-07 15:41  晴天麦芽糖  阅读(212)  评论(0编辑  收藏  举报