C problem: What does void strcpy(char *buffer, char const *string) mean?

what does this statement mean??
void strcpy(char *buffer, char const *string)

Replies

  • friendster7
    friendster7
    char C string handling - Wikipedia(char *, const char *); copies a string from one location to another
  • friendster7
    friendster7
    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'.
  • pradeep_agrawal
    pradeep_agrawal
    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
  • pradeep_agrawal
    pradeep_agrawal
    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

You are reading an archived discussion.

Related Posts

Can anyone guide me on why the DC load-line for a class A transformer coupled power amplifier is verticle?[I am aware that vcc=vce but still unsure why.]Thanks for helping!
I wish we were bigger and had our own teams working on this! Have you guys heard about the Google Lunar X Prize? ๐Ÿ˜ About the prize: The Google Lunar...
guys i think their is no interaction at all here..can their be any suggestion's to make some interaction in this forum... their may be lot of members registering but they...
Hi all.. Please suggest me a project which i can do in java.. which looks a little innovative.. and is a new concept.. Plez help me out!!!
We have talked about this on CE. Look at what Rediff has to say - Source: The coming death of Indian outsourcing The coming death of Indian outsourcing India is...