User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:string.h:strcpy
click
to support this page (eg 0,42 € or so) Thanks.

strcpy

#include <string.h>
char *strcpy(char *str1, const char *str2);

Description

strcpy copy a c string pointed by str2 into the array pointed by str1 including the terminating null character.

strcpy C Example Code

/* 
 * strcpy c example code
 * http://code-reference.com/c/string.h/strcpy 
 */
#include <stdio.h> /* including standard library */
#include <string.h>
 
int main( void ) 
{
  char string[] = "copy me"; /* the size of the array is calculated automatically */
  char string2[20];
 
 
  if( strcpy(string2, string) != 0 )
    printf( "copy success: %s\n",  string2 );
  else
    printf( "copy failure\n" );
  return 0;
}

Output of strcpy example

  user@host:~$ ./strcpy 
  copy success: copy me
advertising
c/string.h/strcpy.txt · Last modified: 2014/04/05 05:04 by 188.113.222.212

Impressum