项目一改变数组串

来源:互联网 发布:网络财经视频直播 编辑:程序博客网 时间:2024/04/30 01:19

【项目1-小心地放开玩字符串/字符数组】
(1)读程序,请分析其实现的功能

* /

* Copyright (c) 2011, 烟台大学计算机学院

 * All rights reserved.

* 作 者: 孙培培

* 完成日期:2012 年 12月13 日

* 版 本 号:v1.0

 * 输入描述:

* 问题描述:

* 程序输出:

 * 问题分析:

*/
#include <iostream>
using namespace std;
int main()
{
 char str1[50]="I  tell  you  that  I  will  be  strongwilled.",str2[50];
 int i=0,j=0;
 cout<<"原字符串:I  tell  you  that  I  will  be  strongwilled."<<endl;
  for(i=0;str1[i]!='\0';i++)
  {
   if(str1[i]!=' ')
   {
     str2[j]=str1[i];
     j++;
   }
  }
  str2[j]='\0';   //切记
  cout<<"整理后的字符串为"<<endl<<str2<<endl;
return 0;
}