C Program to Copy String Without strcpy

This C program copies string without using string handling function strcpy().

C Source Code: String Copy Without strcpy()


#include<stdio.h>

int main()
{
	char str1[30], str2[30];
	int i;

	printf("Enter string:\n");
	gets(str1);

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

	str2[i] = '\0';

	printf("Copied string is: %s", str2);

	return 0;
}

Output

Enter string:
Welcome to C ↲
Copied string is: Welcome to C

Note: ↲ represents ENTER key is pressed.