C Programming Tutorial

Advertisements

Write a program to copy one string to another in C



       #include<stdio.h>
       #include<conio.h>

       void main()
       {

              char str1[50],str2[50];
              int i;
              clrscr();

              printf("\nEnter any string : ");
              gets(str1);
              
              for(i=0;str1[i];i++)
                     str2[i] = str1[i];

              str2[i] = '\0';
              
              printf("\nAfter copying string 2 is : %s",str2);

              getch();
    }

   Output : 

              Enter any string : I love my country
              After copying string 2 is : I love my country




Advertisement