Use C strcpy function to copy a string
Syntax
C strcpy function has the following format.
char *strcpy(char *str1, const char *str2);
Header
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.