strcpy

Overview :

The "strcpy" is used for copying all the characters of string1 to string2..

Syntax :
char *strcpy(char *dest,const char *src);
Description :

The "strcpy" function accepts 2 arguments

  • char *dest -> string buffer where the string will be copied from "src"


  • char *src -> string to be copied


  • strcpy() copies all the characters pointed to by "src" to destination string pointed by "dest" including the terminating NULL character.
    The "dest" string must be large enough to accomodate the "src" string.

The 'strcpy' function returns a pointer to the destination string.
Example :
#include<iostream.h>
#include<string.h>
#include<conio.h>

int main()
{
  char str[10],str1[10];
  cout<<"enter string ";
  cin>>str;

  strcpy(str1,str);
  cout<<str1;
  return 0;
}

Comments

comments powered by Disqus