How to add additional character in multiple places of an array string
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I m not looking for a readymade codes..i just need the logic..its a usual question..but i have some constraints over it.
Also i am not writing a simple C++..i am going to modify a ns2 module and it just a function. Thats why, i m posting it here.
I updated my post..so kindly check it once..Please i am very new to field..
So help me out !!!
Thankx !!
Last edited by newinubuntu; 05-07-2015 at 11:47 AM.
So you created some variables ... good start. Where is the loop you mentioned to cycle through each character in your array (string) to then allow you to build the new array with the additional
characters?
One thing you'll want to do, right away, is to slurp the values from that character-array (which now contains "ironman") into a true C++ string type. Do your subsequent manipulations using that string. Then, after checking to be sure that the output buffer is large enough to hold the value (and a terminating \0 byte!), transfer the finished string back into that buffer.
If you can't use regular-expressions and so forth, then you'll basically be taking substring-slices from one string, which is your "source," and concatenating them into another string, which will become your "final result." This string will be the one that you copy back into your result buffer, after verifying its size as aforesaid. You do nothing-at-all with that buffer between the time that you slurp the existing value from it and when you pour the result back into it.
The procedure is, "a bit tedious, yes, but entirely straightforward."
(Generally, in C++, there is very little use for "a fixed-size array-of-char." Use the string type, instead. It's faster, more efficient, has no size constraints, can understand Unicode, and so on.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.