C program to copy one string to another string without using strcpy() and using for Loop.












C program to copy one string to another string without using strcpy() and using for Loop.




C program to copy one string to another string without using strcpy() and using for Loop.



#include <stdio.h> #define MAX 200 int main() { char text1[MAX]; char text2[MAX]; int i; printf("\n Enter any string: "); gets(text1); for(i=0; text1[i]!='\0'; i++) { text2[i] = text1[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: computer First string = computer copy string = computer Total characters copied = 8




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