C program to copy one string to another string using while Loop.












C program to copy one string to another string using while Loop.




C program to copy one string to another string using while Loop.



#include <stdio.h> #define MAX 200 int main() { char text1[MAX]; char text2[MAX]; int i; printf("\n Enter any string: "); gets(text1); i=0; while(text1[i] != '\0') { text2[i] = text1[i]; i++; } text2[i] = '\0'; printf("\n First string = %s", text1); printf("\n Copy string = %s", text2); printf("\n Total characters copied = %d", i); return 0; }


Output:
Enter any string: c programming language First string = c programming language Copy string = c programming language Total characters copied = 22




Exercise: 1
C program to copy one string to another string.