0

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.

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by ssmg
1

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));
0

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

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

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

string sent = "ILoveYouMary";
string sub = sent.substr(5); //"YouMary"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.