Thread: Regarding 'strdup()'

  1. #1
    Registered User
    Join Date
    Sep 2009

    Question Regarding 'strdup()'

    Hi friends,

    Can anyone tell me what is the purpose of strdup() function in C/C++??

    Thanks in Advance!!!!!

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    It just makes a copy of a string, returning a malloc'ed chunk of memory. Not standard, AFIAK.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well in C++, it's a waste of space, because std::string objects (which you should be using for everything you can use it for) supports assignment - so making a copy of a string is a breeze.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 11-11-2007, 10:40 AM
  2. Question to do with strdup()
    By John.H in forum C Programming
    Replies: 9
    Last Post: 01-29-2003, 10:30 AM
  3. strdup
    By hankspears in forum C Programming
    Replies: 4
    Last Post: 05-09-2002, 02:02 PM
  4. function: strdup()
    By cjtotheg in forum C Programming
    Replies: 3
    Last Post: 02-02-2002, 10:08 AM
  5. strcpy and strdup?
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 10-26-2001, 06:46 AM