Skip to content
Home » C Programs » C Program to Implement Strcpy Function

C Program to Implement Strcpy Function

Simple string copy function in c. Using this program we can copy the value of the variable in the c program which is stored in the variable. strcpy() is a C/C++ standard library function for copying one string to another. It can be found in the string.h header file in C and the cstring header file in C++.

Strcpy Function in C

To copy strings, use the strcpy() function. It copies the string specified by source into the destination. This function takes two pointer to char or array of characters arguments and returns a pointer to the first string that is destination.

The strcpy() function is a standard library function. It is used to copy a string from one location to another. In C, it is declared in the “string. h” header file, whereas in C++, it is declared in the “cstring” header file. It returns the destination pointer. Here we have executed the string copy function in c

Char in C Program

To store characters and letters, C employs the char type. However, the char type is an integer type because C stores integer numbers rather than characters. Char values in C are stored in 1 byte of memory and have a value range of -128 to 127 or 0 to 255.

String in C

In C, a string is simply a collection of characters in a linear sequence. Even if a string contains whitespaces, ‘C’ always treats it as a single data point. The length(string) function is the most basic example of a string function. The length of a string literal is returned by this function. Using this program we can execute string copy function in c.

Array Concept in C Program

An array is defined as a collection of data items of the same type that are stored in contiguous memory locations. Arrays are derived data types in the C programming language that can store primitive data types such as int, char, double, float, and so on.

String Copy Function in C

//string copy function in c
#include<stdio.h>
#include<string.h>
int main()
{
char s1[10], s2[10];
strcpy(s1, "noteshippo.com"); 
strcpy(s2, s1); 
printf("%s\n", s2);
return(0);
}

Output of string copy function in c:

noteshippo.com