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] != '\0'&& str[i+1] != '\0')
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] = '\0';
34 }