Copy One Character Array to Another Character Array
“Copy One Character Array to Another Character Array” is a basic operation of character array. Here, we are given a character array of length ‘n’. Our task is to copy given character array to another without using any in-built function.
The steps required to copy given character array to another is as follows:
- Create a temporary character array of same size as of original character array.
- Scan the complete character array and copy character by character to temporary character array.
C++ Program to copy character array to another character array is as follows:
#include<bits/stdc++.h>
using namespace std;
int main()
{
char str[len];
cout<<"Enter the string:\n";
cin>>str;
int length = strlen(str);
char temp[length+1];
for(int i = 0; i < length; i++)
{
temp[i] = str[i];
}
temp[length] = ' #include<bits/stdc++.h> using namespace std; int main() { char str[len]; cout<<"Enter the string:\n"; cin>>str; int length = strlen(str); char temp[length+1]; for(int i = 0; i < length; i++) { temp[i] = str[i]; } temp[length] = '\0'; cout<<"\nThe Temporary String is: "<<temp; }
';
cout<<"\nThe Temporary String is: "<<temp;
}
OUTPUT: Enter the string: helpmestudybro The Temporary Array is: helpmestudybro Time Complexity: O(n), where n is the length of string.
Related Posts:
- Program to Concatenate Two Strings.
- Program to Check whether given String is Palindrome or not.
- Program to convert lower-case alphabet to upper-case alphabet and vice-versa.
- Program to count total number of words in a string.
- Program to find smallest and largest word of the String.
- Program to find Most Frequent Character of the String.
- Program to Remove all the blank spaces from the String.
- Program to check if String is isogram or not.
- Program to Reverse Each word of the String.
- Program to Print All the Substring of the Given String.
- Program to find longest palindromic Substring.
- Program to check Anagram Strings.
- Program to check whether two Strings are Rotation of each other or not.
- Program to check Palindromic Anagram.
- Program to print all the Palindromic Substring of the String.
- Program to check Panagram String.
- Program to find first non-repeating character of the String.
- Program to Rotate Array Elements by ‘D’ positions.
- Program to find most frequent element in an array.
- Program to find pair in an array with given sum.