Question 5: Write a C++ program that takes two strings as input and concatenate one  string contents to another.

February 13, 2019
Question 5: Write a C++ program that takes two strings as input and concatenate one  string contents to another.
/*
Name:                   Mudassar Ali
Roll:                   BCSF15M045   [Morning]
Assignment:             No# 05
Teacher:                Miss Sadia Shahzad
*/

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    cout<<"This programme will concatenate two strings!!\n\n";

    char str1 [50];      // To hold the contents of string one
    char str2 [50];      // To hold the contents of string second
    cout<<"Enter the string one: ";
    cin>> str1;          // Inputting string one.
    cout<<"Enter the string two: ";
    cin>> str2;          // Inputting string two.
    int i;               // variable for loop.
    for( i =0;str1[i]!='\0';i++);  //To load the string contents till NULL.

        {
        for(int x=0;str2[x]!='\0';x++,i++) // In this loop second sting contents loaded and assign to string one after the loaded contents
        str1[i] = str2[x];                 // of string one.
        }

    str1[i] = '\0';                       // Placing the NULL at the last of string one.

    cout<<"\nConcatenated String is: "<<str1<<endl;

return 0;
}





No comments:

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();
Powered by Blogger.