Write C program to copy one string to another string


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write C program to copy one string to another string


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

Result

C language techstudy.org

     





Related Topics




Popular Posts