对于清除字符串中空格

来源:互联网 发布:云购cms qq回调地址 编辑:程序博客网 时间:2024/05/17 02:02

   在c语言中,调用isspace()来清除一串字符串中的空格,

例题 “   abcdef647ykfkfg     ”,将该字符串中的空格去掉,计算字符个数,并返回该字符串。

程序如下:

include<stdio.h>

include<stdlib.h>

include<string.h>

int  trimspace(char *inbuf,char *outbuf)

{

      int count = 0;

      char *p = inbuf;//不改变一级指针的内存值

          int i = 0;

      int j = 0;

      int len = strlen(p);

      j = len-1;

     while(isspace(p[i]) && p[i]!='\0')

{

    i++;

}

    while(isspace(p[j]) && j>0)

{

   j--;

}

   count = j-i+1;

 

    

}

int main()

{

     char *str = "    abcd67857sgjhsd      "; 

     trimspace(str,out);

    memcpy(str,out);

}

1 0
原创粉丝点击