0709 C语言----------字符串去空格

 1 /*************************************************************************
 2     > File Name: main.c
 3     > Author:Monica
 4     > Mail:liling222@126.com 
 5     > Created Time: Mon 07 Jul 2014 04:29:35 PM CST
 6  ************************************************************************/
 7 #include <string.h>
 8 #include <stdio.h>
 9 int main()
10 {
11     char buf[] = "  cd  \home";
12     int cur = -1, index = 0;
13     printf("before buf:%s", buf);
14     for(; index <strlen(buf); index++)
15     {
16         if(buf[index] != ' ' &&  buf[index] != '
')
17         {
18             buf[++cur] = buf[index];
19         }
20         else
21         {
22             if(cur != -1 && buf[cur] != ' ' && buf[cur] != '
')
23             {
24                 buf[++cur] = buf[index];
25             }
26         }
27     }
28     for(; cur>=0; cur--)
29     {
30         if(buf[cur] != ' ')
31             break;
32     }
33     buf[++cur] = '';
34     printf("after buf:%s", buf);
35     return 0;
36 }
原文地址:https://www.cnblogs.com/monicalee/p/3829996.html