HP C/iX Library Reference Manual (30026-90004)

Chapter 5 335
HP C/iX Library Function Descriptions
strcpy
strcpy
Copies the contents of
s2
into
s1
.
Syntax
#include <string.h>
char *strcpy(char *
s1
, const char *
s2
);
Parameters
s1
A pointer to the target string.
s2
A pointer to the source string.
Return Values
x The value of
s1
.
Description
In the strcpy function,
s2
is a character pointer to the string to be copied, and
s1
is a
character pointer to the beginning of the string into which the contents of string
s2
are
copied. The strcpy function copies the entire string, up to and including the first null
encountered. Use strlen() and memmove() rather than strcpy() if the string at
s2
overlaps
s1
; otherwise, the behavior is undefined.
Examples
The following program uses the strcpy function and the strcat function to build a
character string representing the lowercase alphabet, one character at a time:
#include <stdio.h>
main()
{
int b = 'b', z = 'z', i;
char alpha[30], chr[4];
chr[1] = NULL;
strcpy(alpha, "a");
printf("%s\n", alpha);
for(i = b; i <= z; i) {
chr[0] = i;
strcat(alpha, chr);
printf("%s\n", alpha);
}
}
The array chr is always going to be a two-character array consisting of the next character
in the alphabet followed by a null character. Thus, the second element of chr is set to a null