C library function — strcpy()

Introducation -

In this tuto­r­i­al i will explain you str­cpy() func­tion in c pro­gram­ming. str­cpy() func­tion in c, copy one string into anoth­er string. In C str­cpy c is avail­able in string.h head­er file.

Why do u need strcpy() function ?

We can’t assign one string into anoth­er string using assign­ment oper­a­tor that is why we need str­cpy() func­tion. Let’s take an exam­ple -

We have cre­at­ed two vari­able a and b, vari­able a con­tains val­ue 10 but vari­able b is emp­ty. We can assign vari­able a val­ue to vari­able b using assign­ment oper­a­tor.

In case of string i want to do sim­i­lar kind of oper­a­tion then it is not allowed in C using assign­ment oper­a­tor and below giv­en exam­ple is wrong.

Syntax -

des­ti­na­tion : Point­er to the des­ti­na­tion array where the con­tent is to be copied.

source : This is string which will be copied. It might be string vari­able or string con­stant.

Example Program -

Output -

strcpy c