编写函数,要求去掉字符串的所有空格。
要求:
(1)定义函数del(char s[]),s为存入字符串的数组,将字符串的字符从前往后依次判断,如为空格则删除,并将后面的所有字符依次前移一个位置。
(2)编写一个主函数,输入字符串,调用(1)的函数后,在主函数中输出结果。

编写函数,要求去掉字符串的所有空格。
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- bekote 2021-11-18 22:36关注
#include <iostream> using namespace std; void del(char s[]){ int j=0; for(int i=0;s[i]!='\0';i++){ if(s[i]==' '){ continue; } s[j++]=s[i]; } s[j]='\0'; } int main() { char s[10000]; cin.getline(s,10000); del(s); cout<<s; return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用 2