C programming strcpy – strcpy C Library Function

C programming strcpy: The function char *strcpy(char *destination, const char *source); copies the string pointed by source into the string pointed by destination including the null character(‘\0’).

Function prototype of strcpy

char *strcpy(char *destination, const char *source);
  • destination : This is pointer to a string where the content is to be copied.
  • source : This is pointer to a string from where data to be copied.

Return value of strcpy

Strcpy c program: This function returns a pointer to destination string.

C program using strcpy function

Strcpy in c: The following program shows the use of strcpy function to copy a string into another string.

strcpy C Library Function

#include <stdio.h>
#include <string.h>
#include <conio.h>
 
int main ()
{
   char source[100], destination[100];
 
   printf("Enter source string\n");
   gets(source);
    
   strcpy(destination, source);
    
   printf("Destination string : %s\n", destination);
    
   getch();
   return(0);
}

Output

Enter source string
TechCrashCourse
Destination string : TechCrashCourse