C Program to Copy String

In this tutorial you will learn about the C Program to Copy String and its application with practical example.

C Program to Copy String

In this tutorial, we will learn to create a C program that will Copy String in C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • Using Strings in C Programming.

What is a string?

As we all know, the string is a collection of characters, symbols, digits, and blank spaces. In strings, only one variable is declared which can store multiple values.

Algorithm:-

Program to Copy String 

First, will take the input string from the user. And then will copy the string. The C programming language has many pre-defined functions for string manipulation. In today’s tutorial, we will do copy work with the help of a strcpy() function. It is used for copying the string from one variable to another variable.

With the help of the below program, we can Copy String.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • var1 = it will hold the string value.
  • var2 = it will hold the string value.

Taking input string from the user for copying the string.

Copying the string with the help of the assignment operator.

Printing the output copied string1 and string2.

In this tutorial we have learn about the C Program to Copy String and its application with practical example. I hope you will like this tutorial.