Use C strcpy function to copy a string

Syntax

C strcpy function has the following format. char *strcpy(char *str1, const char *str2);

C strcpy function is from header file string.h.

Description

C strcpy function copies *str2 into *str1. *str2 must be a pointer to a null-terminated string. C strcpy function returns a pointer to str1.

Example

Use C strcpy function to copy a string.


#include<string.h>
#include<stdio.h>
/*  w ww.j av a 2  s . c  o  m*/
int main(void){
  char str[80];
  strcpy(str, "hello");
  printf("%s", str);
}

The code above generates the following result.





















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h