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:

  1. Create a temporary character array of same size as of original character array.
  2. 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:

  1. Program to Concatenate Two Strings.
  2. Program to Check whether given String is Palindrome or not.
  3. Program to convert lower-case alphabet to upper-case alphabet and vice-versa.
  4. Program to count total number of words in a string.
  5. Program to find smallest and largest word of the String.
  6. Program to find Most Frequent Character of the String.
  7. Program to Remove all the blank spaces from the String.
  8. Program to check if String is isogram or not.
  9. Program to Reverse Each word of the String.
  10. Program to Print All the Substring of the Given String.
  11. Program to find longest palindromic Substring.
  12. Program to check Anagram Strings.
  13. Program to check whether two Strings are Rotation of each other or not.
  14. Program to check Palindromic Anagram.
  15. Program to print all the Palindromic Substring of the String.
  16. Program to check Panagram String.
  17. Program to find first non-repeating character of the String.
  18. Program to Rotate Array Elements by ‘D’ positions.
  19. Program to find most frequent element in an array.
  20. Program to find pair in an array with given sum.

You may also like...