CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

INSERT command

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

INSERT command
PostPosted: Mon Feb 10, 2014 8:42 pm     Reply with quote

im string to convert some code, and INSERT is not in a stdlib.h

i was thinking strCat would work the same.?
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Feb 11, 2014 1:23 am     Reply with quote

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
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Tue Feb 11, 2014 1:41 am     Reply with quote

thank you Smile

this has helped!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group