#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#define SIZE 40
char* de_blank(char*);
char* s_gets(char*, int);
int main(void)
{
char arr[SIZE];
while (1)
{
printf("请输入一串字符串:\n");
s_gets(arr, 40);
if (*arr == '\0')
break;
printf("除去空格的字符串为:\n");
puts(de_blank(arr));
}
return 0;
}
char* de_blank(char* st)
{
int n;
int i = 0;
int j;
char c;
n = strlen(st);
while (st[i] != '\0')
if (st[i] == ' ' || st[i] == '\t')
{
j = i;
while (st[j] != '\0')
{
st[j] = st[j + 1];
j++;
}
}
else
i++;
st[i] = '\0';
return st;
}
char* s_gets(char* st, int n)
{
char* ret_val;
ret_val = fgets(st, n, stdin);
while (*st != '\n' && *st!='\0')
st++;
if (*st == '\n')
*st = '\0';
else
while (getchar() != '\n')
continue;
return ret_val;
}