String is very Important data type in all types of Programming. String contains the text data and we need it almost in every Programming problems. 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
Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of
BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
This comment has been removed by a blog administrator.
ReplyDelete