+ Reply to Thread
Results 1 to 2 of 2

Thread: What should I use strncpy or strcpy?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    46

    What should I use strncpy or strcpy?

    What should I use strncpy or strcpy?

    I heard that strncpy is safe than strcpy. How is it?

    Thanks.

  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    38
    strcpy copies source string to destination string.

    Sometimes it is not safe if a third party application provides source string which can be arbitrary length.

    Destination may have not enough space to copy the source string!

    So it is always safe to use strncpy which takes one more parameter that tells that how many number of characters it should copy to destination.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts