To copy the contents of one string to another string

This is the simple implementation of the “Copy” function of the computer world. This program copies the content of one string to another.

Logic : The program asks the user to input the string to copy and stores this as str1. The inner function “stcpy” takes 2 strings as arguments. By keeping the length as the reference, it traces till EOL , for each i of this iteration, it copies the i-th  letter to the destination string, i.e str2.

After the EOL, it puts a NULL to the second line. That gives the duplicated string of the entered.

void stcpy(char str1[50], char str2[50]);
void main()
char str1[50], str2[50];
printf(“\n\n\t ENTER A STRING…: “);
printf(“\n\t THE COPIED STRING IS…: “);
void stcpy(char str1[50], char str2[50])
int i, len = 0;
str2[i] = str1[i];
str2[i] = ‘\0’;
Download exe and source code here.

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

Leave a Reply

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

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.