Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Feb 11, 2014 1:23 am |
|
|
Insert, is a c++, or c# command, not a C command. Hence it not being in stdlib....
However everything it does, can be produced using the standard C string functions. Key thing is though which of the various forms of 'insert' you wish to use. Insert is an overloaded function, supporting inserting single characters, strings, or a number of characters from a string.
Several people have published C code to do this for a string:
<http://www.programmingsimplified.com/c/source-code/c-program-insert-substring-into-string>
Which covers the commonest form. Using strcat, and strcpy. However 'beware', since this is using 'free' to re-allocate space, which won't work unless the space is allocated using malloc, which isn't done in this example. Free used like this in CCS will give undefined behaviour. However it is fairly simple to not use free at all here.
For inserting a single character, look at:
<http://cboard.cprogramming.com/c-programming/144450-insert-char-anywhere-string.html>
Again look at the 'caveats' about string space.
Best Wishes |
|