Hi friends,
Can anyone tell me what is the purpose of strdup() function in C/C++??
Thanks in Advance!!!!!
Hi friends,
Can anyone tell me what is the purpose of strdup() function in C/C++??
Thanks in Advance!!!!!
It just makes a copy of a string, returning a malloc'ed chunk of memory. Not standard, AFIAK.
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.