/*
编写一个函数接受一个字符串作为参数,并删除字符串中的空格。
在一个程序中测试该函数,使用循环读取输入行,直到用户输入一行空行。
该程序应该应用该函数读取每个输入的字符串,并显示处理后的结果。
*/
#include<stdio.h>
#define SIZE 40
void del_space(char str[]);
int main(void)
{
char string[SIZE];
int i = 0;
while ((string[i] = getchar()) != '\n' && i < SIZE)
i++;
string[i] = '\0';
del_space(string);
puts(string);
return 0;
}
void del_space(char str[])
{
int i = 0;
while (str[i] != '\0')
{
if (str[i] == ' ')
{
int j;
j = i;
while (str[j] != '\0')
{
str[j] = str[j + 1];
j++;
}
}
i++;
}
}
C PRIMER PLUS(第六版编程练习)11.13编程练习_10题
最新推荐文章于 2023-01-06 21:15:38 发布