Friday 12 August 2016

Copy one string to another without using library function strcpy

Copy one string to another without using library function strcpy


#include<stdio.h>
main()
{
                char s1[10], s2[10];
                int n, i = 0;
                printf("\nEnter string 2: ");
                gets(s2);

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

                printf("\n String 1 after copying: ");
                puts(s1);
}

Output:
Enter string 2: Hello Hii
String 1 after copying: Hello Hii

No comments:

Post a Comment