C program to copy the contents of one string to another without strcpy() function

//C program to copy the contents of one string to another without strcpy() function
 
#include <stdio.h>
int main()
{
	char string1[100], string2[100], i;
	printf("Enter string 1: ");
	scanf("%s", string1);
	for (i = 0; string1[i] != '\0'; ++i)
	{
		string2[i] = string1[i];
	}
	string2[i] = '\0';
	printf("String 2: %s", string2);
	return 0;
}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s