Jump to: navigation, search

Prototype

Declared in string.h

In C90, the prototype is:

char *strcpy(char *dest, const char *src);

The C99 prototype is identical but adds the new restrict qualifiers:

char *strcpy(char * restrict dest, const char * restrict src);

Description

The strcpy() function shall copy the null-terminated string pointed to by src to the memory pointed to by dest. Source and destination may not overlap.

Return value

The strcpy() function shall return the pointer dest; the function has no failure mode and no error return.

Implementation

In standard C, this can be implemented as:

#ifdef _NC_RESTRICT
char *strcpy(char *restrict dest, const char *restrict src)
#else
char *strcpy(char *dest, const char* src)
#endif
{
    char *ret = dest;
    while (*dest++ = *src++)
        ;
    return ret;
}

Compilable unit, strictly conforming C90 in implementation namespace; public domain; past reviewers: none; current reviews: none

Non-portable components

References

Personal tools