首页 > 代码库 > 0707 Linux小结----------去空格

0707 Linux小结----------去空格

 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] != \n)17         {18             buf[++cur] = buf[index];19         }20         else21         {22             if(cur != -1 && buf[cur] !=   && buf[cur] != \n)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] = \0;34     printf("after buf:%s", buf);35     return 0;36 }