strcpy() Function


The strcpy() method works almost like a string-assignment operator. It takes the form :

strcpy(str1,str2);

and assigns the contents of str2 to str1. str2 may be a character array variable or a string constant. For example, the statement

strcpy(str1,str2);
strcpy(str1,"hello");

Sample Program

Program
#include <stdio.h>
#include <string.h>

int main() {
  char str1[50] = "VERY";
  char str2[20] = "GOOD";
  
  printf("%s\n",strcpy(str1,str2));
  printf("%s\n",strcpy(str1,"Hello"));
  return 0;
}