C program to copy one string to other without using library function

C program to copy one string to other without using library function:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>

main()
{
   char s1[100],s2[100];
   int i=0;

   printf("Enter any string :");
   gets(s1);

   while(s1[i] != '\0')
    {
      s2[i] = s1[i];
      i++;
    }

   s2[i] = '\0';
   printf("\nCopied String is %s ", s2);
}

OUTPUT:

Enter any string :BaronTuts

Copied String is BaronTuts

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.