CrazyEngineers
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • friendster7

    MemberMar 2, 2008

    char <a href="https://en.wikipedia.org/wiki/Strcpy" target="_blank" rel="nofollow noopener noreferrer">C string handling - Wikipedia</a>(char *, const char *); copies a string from one location to another
    Are you sure? This action cannot be undone.
    Cancel
  • friendster7

    MemberMar 2, 2008

    let us say

    char *s1; points to an area of memory that is to receive the copied characters. const char *s2; points to the string from which characters will be copied. This must end with the usual '\0'.
    Are you sure? This action cannot be undone.
    Cancel
  • pradeep_agrawal

    MemberMar 2, 2008

    The prototype is: void strcpy(char *buffer, char const *string);

    The function copies the string pointed by variable 'string' to variable 'buffer', i.e., it copies each character starting from the memory location pointed by variable 'string' to to the memory location starting from the one pointed by variable 'buffer'. The function copies the characters till it encounter character '/0' (character having ASCII value 0, represents end of string).

    The use of const in 'char const *string' means that variable 'string' is pointer to constant characters, so you can't modify the string represented by variable 'string'.

    -Pradeep
    Are you sure? This action cannot be undone.
    Cancel
  • pradeep_agrawal

    MemberMar 2, 2008

    But its better to use errno_t strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource); instead of strcpy.

    Consider case that your destination buffer is of size 128 and source string has length greater then 128. In such case the code will cause crash.

    In strcpy_s, 'size_t numberOfElements' specifies the size of destination string buffer and it returns 0 if copy is successful otherwise returns the error code.

    -Pradeep
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register