Regarding 'strdup()'

This is a discussion on Regarding 'strdup()' within the C++ Programming forums, part of the General Programming Boards category; Hi friends, Can anyone tell me what is the purpose of strdup() function in C/C++?? Thanks in Advance!!!!!...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    26

    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
    Location
    Waterloo, Texas
    Posts
    5,699
    It just makes a copy of a string, returning a malloc'ed chunk of memory. Not standard, AFIAK.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 11-11-2007, 09:40 AM
  2. Question to do with strdup()
    By John.H in forum C Programming
    Replies: 9
    Last Post: 01-29-2003, 09: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, 09:08 AM
  5. strcpy and strdup?
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 10-26-2001, 06:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21