User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

Q&A is closed



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


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
#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 );
    printf( "copy failure\n" );
  return 0;

Output of strcpy example

  user@host:~$ ./strcpy 
  copy success: copy me

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/string.h/strcpy.txt · Last modified: 2024/02/16 01:06 (external edit)

Impressum Datenschutz