当函数发现字符串中如果有一个地方由一个或多个连续的空格组成,就把它们改成单个空格字符。

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 void deblank(char str[]);
 5 int main()
 6 {
 7     char str[100] ;
 8     memset(str,0,100);
 9     printf("please input the string str:");
10     gets(str);
11     deblank(str);
12     puts(str);
13     system("pause");
14     return 0;
15 }
16 void deblank(char str[])
17 {
18     int i = 0;
19     int j = 0;
20     while(str[i] != ''&& str[i+1] != '')
21     {
22         if(str[i] != ' ' || (str[i] == ' ' && str[i+1] != ' '))
23         {
24            str[j] = str[i];
25             j++;
26             i++;
27         }
28         else
29             {
30                 i++;
31         }
32     }
33     str[j+1] = '';
34 }
原文地址:https://www.cnblogs.com/joyclub/p/4480305.html