Hi everyone;
I have a character array of 13 elements and I already defined the first 5 ones. The rest chars are constant so all I need to do is assign the chars between 6-12 instead of writing them one by one.To make it clearer, say my string is "ILoveYouMary" and I already assigned "ILove" part and I need to assign the rest of the array i.e "YouMary" to my char variable at once.
I want to do it in a go, rather than go line by line and
variable[6]='Y';
variable[7]='o';
varialbe[8]='u';
.
.
.
Thank you.Have a good day.
Cheers.

Recommended Answers

All 4 Replies

I'm not sure there is syntaxically correct way provided by C++ (or C legacy stuff), but here is one slightly dirty way to get it done:

memmove(variable + 6, "YouMary", 7 * sizeof(char));

Well thats what a for loop is for. Or you can use strings

string sent = "ILoveYouMary";
string sub = sent.substr(5); //"YouMary"

Well thats what a for loop is for. Or you can use strings

string sent = "ILoveYouMary";
string sub = sent.substr(5); //"YouMary"

Thank you everyone for the replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.