Write C++ program to copy one string to another string


I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. #define MAX_SIZE 100 // Maximum size of the string
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. char text1[MAX_SIZE], text2[MAX_SIZE];
  8. char * str1 = text1;
  9. char * str2 = text2;
  10.  
  11. // Inputting string from user
  12. cout<<"Enter any string: "<<endl;
  13. cin>>text1;
  14.  
  15. // Coping text1 to text2 character by character
  16. while(*(str2++) = *(str1++));
  17.  
  18. cout<<"First string: "<<text1<<endl;;
  19. cout<<"Second string: "<<text2<<endl;
  20.  
  21. return 0;
  22. }
  23.  

Result

C++ language techstudy.org

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.