Friday, 26 August 2016

C Program on string copy without using strcpy()

A simple C program on string copy without using library function strcpy(). Here we read each character in the first string until the end and copy it to the second string.

Refer below for screenshot and program,



Download code

PROGRAM : 

#include<stdio.h>

int main()
{
    char str1[100],str2[100];
    int i=0;

    printf("Enter a string: ");
    gets(str1);

    while(str1[i]!='\0')
    {
        str2[i] = str1[i];
        i++;
    }
    str2[i]='\0';

    printf("\nCopied String: %s\n",str2);
    return 0;
}
Download code

OUTPUT :  

C Program on string copy without strcpy()