Strdup: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
m (clean up, added stub, deadend tags)
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Defined as static functions in <code>src\vgui2\controls\BitmapImagePanel.cpp</code> and as <code>CopyString</code> in <code>src\dlls\AI_ResponseSystem.cpp</code>, this function simply returns a pointer to a clone of the string parameter.  This function handles the repetative code that is seen when copying a string and makes it an inline function.  If copied to <code>src\game_shared\util_shared.h</code>, this function could come in handy at times.
{{Dead end|date=January 2024}}
inline char *CloneString( const char *str )
{{DISPLAYTITLE:strdup}}
{
== char *'''strdup'''(const char *s1) ==
char *cloneStr = new char [ strlen(str)+1 ];
strdup is a standard C/C++ function and is useful for '''dup'''licating '''str'''ings to store them off to pointers. Remember to delete the duplicated string once you're done with it.
strcpy( cloneStr, str );
 
return cloneStr;
}
[[Category:Helpers]]
[[Category:Helpers]]
[[Category:Functions]]
{{stub}}

Latest revision as of 10:16, 21 January 2024

Dead End - Icon.png
This article has no Wikipedia icon links to other VDC articles. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024

char *strdup(const char *s1)

strdup is a standard C/C++ function and is useful for duplicating strings to store them off to pointers. Remember to delete the duplicated string once you're done with it.


Stub

This article or section is a stub. You can help by expanding it.