13週目アイテム5-文字列アクション(2.4)
問題の説明:
(2)次のプログラムを読み,類似文字列コピーの機能を果たす.
それぞれのプログラムを作成し、次の処理を完了してください.
(4)str 1とstr 2を接続し、str 1に格納する.
コード:
実行結果:
(2)次のプログラムを読み,類似文字列コピーの機能を果たす.
#include<iostream>
using namespace std;
int main()
{
char str1[50]="I am a happy boy\'s daddy.",str2[50];
int i=0,j=0;
while(str1[i]!='\0')
{
if(str1[i]!=' ')
{
str2[j]=str1[i];
j++;
}
i++;
}
str2[j]='\0';// !!
cout<<" "<<str2<<endl;
return 0;
}
それぞれのプログラムを作成し、次の処理を完了してください.
(4)str 1とstr 2を接続し、str 1に格納する.
コード:
#include<iostream>
using namespace std;
int main()
{
char str1[100]={"One thorn of experience is worth a whole wilderness of warning."};
char str2[100]={"(James Russell Lowell, British Poet and critic) "};
int i=0,j=0;
while(str1[i]!='\0')
i++;
j=0;
while(str2[j]!='\0')
str1[i++]=str2[j++];
str1[i]='\0';
cout<<" : "<<str1<<endl;
return 0;
}
実行結果: