Saturday, 19 July 2014

How to Copy Text from one String to other String

Structure of the Problem Requirements 

Strings are very Important data type in all types of Programming. String contain the text data and we need it almost in every Program. In this Problem we have three Strings, one contain a sentence and other two string are use to extract that sentence and put that in new String.

Source Code

#include <iostream>
#include <cstring> // prototypes for strcpy and strncpy
using std::strcpy;
using std::strncpy;
using namespace std;
 int main()
  cout<<endl<<endl<<"*************** STRING FUNCTION ******************"<<endl<<endl;\
char x[] = "WELCOME TO RIPHAHIUI BLOG"; // string length 21
char y[ 25 ];
char z[ 15 ];
strcpy( y, x ); // copy contents of x into y
cout << "The string in array x is: " << x
<< "\nThe string in array y is: " << y << '\n';
// copy first 14 characters of x into z
strncpy( z, x, 14 ); // does not copy null character
z[ 14 ] = '\0'; // append '\0' to z's contents
cout << "The string in array z is: " << z << endl;
 return 0; // indicates successful termination
} // end main

Output of the Program

Java String Programming
Java String Programming

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

2 comments: Post Yours! Read Comment Policy!▼
Important Note:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

  1. This comment has been removed by a blog administrator.

    1. thanks JOSH for your precious feed back here. Here we just start basic of C++and will move further topic so be cool and wait for your time of safe programming .