C Programming: strcpy Function Explained with Example
strcpy is a standard library function in C programming language used to copy a string from one location to another. The function takes two arguments: the destination string and the source string. It copies the characters from the source string to the destination string until it reaches the null character '\0'.
Syntax:
char* strcpy(char* destination, const char* source);
Example:
#include <stdio.h>
#include <string.h>
int main () {
char source[] = 'Hello World!';
char destination[20];
strcpy(destination, source);
printf('Source string: %s\n', source);
printf('Destination string: %s\n', destination);
return 0;
}
Output:
Source string: Hello World!
Destination string: Hello World!
原文地址: https://www.cveoy.top/t/topic/ke3s 著作权归作者所有。请勿转载和采集!