Need a project done?

C++ Programming Developer

Search This Blog

Write A function to copy one String into Another. How to copy String in C++? 'Strncpy' in C++


//How to copy String in C++?  'Strncpy' in C++.
//Program to Copy content of one string into another.


#include <iostream>
using namespace std;

int main()
{
const int size = 15;
char string[size] = "He. is.";
char a[size];
strcpy (a,string);
cout << a;
}

//===========================================================================

Write A function to copy one String into Another.


#include <iostream>
using namespace std;

void stringcopy(char s[], int size);

int main()
{
const int size = 15;
char string[size] = "He. is.";

stringcopy(string, size);
cout << string << endl;

return 0;
}

void stringcopy(char s[], int size)
{
char *a = new char [size];
strcpy (a,s);

cout << a << endl;
}

No comments:

Post a Comment

"Don't let anyone ever make you feel like you don't deserve what you want."