I'm trying to make a program that loops through all of the characters in a string and replace each one with a corresponding alteration of the character. How should I start going about this without creating a rule for each separate letter?
ie. cin << "Big Dogs" ---> cout >> "_B__I__G_ _D__O__G__S_"
/dpt/
/sqt/
>>58715284
iterate though your list of chars, uppercasing and adding a _ before/after it.
>>58715304
is this a shitpost?
>>58715284def munge s
'_' + s.upcase.chars.join('__') + '_'
end
'___'
>>58715312
how would I append that through the iteration? are there any chapter in a C++ textbook I should look at for the relevant expressions?
>>58715314
Are you mentally retarded or just a fucking idiot?
>>58715360
google search yielded nothing
>>58715317
getting expression must have class type on s
>>58715411
what does this even mean?
>>58715346
well.. if you don't have a dynamic array/list, you'll have to create another one (since you'll be altering it's size) and for each char read, you put: an underscore, the uppercased char, another underscore, and then just jump 3 units instead of one in the for loop, i guess.
if your array is dynamic there are perhaps better ways of doing it. there are always better ways of doing anything on cs.
cin >> words;
int size = words.size();
for (words; i = 0; i < size) ++i; {
while (i < size); {
":regional_indicator_" + words + ':';
}
}
cout << words;
I know I'm missing something major here but I'm not quite sure what. It's not printing anything and the prompt freezes when ran.
>>58715725
Should I encapsulate something in a function? I'm very lost here and obviously have had no formal education in this. Could anyone point me to any resources that explain this better?
>>58715725
>for (words; i = 0; i < size) ++i;
shouldn't it befor (words; i = 0; i < size; ++i)
?
>>58715284
>how do I loop through a string
for fucks sake this is extremely low quality bait or you are retarded
>>58715830
It should be, but it tells me it is expecing ) after size;
>>58715867
oh my bad, it should be like this:for (int i = 0; i < size; ++i) {
i totally ignored the first section of the for loop
>>58715862
sorry I wasn't born knowing C++ fluently. I'll try to get born better next time.
>>58715867
also, if you really want/need to learn, try getting Lipmann's C++ Primer or just get any book at http:// programming-motherfucker . com /
(it's a real site, i'm not joking lol)
>>58715880
Oh, yeah that worked. Thanks.
>>58715893
Try to get aborted next time, you dumb fucking shit stain.
>>58715900
I'll pirate whatever I can from the motherfuckers site tonight and start reading tomorrow. I was hoping I could finish this tonight, but there's no way.
>>58715937
if you worked up over something so trivial, your life must suck dude. i kinda feel sorry for you.
their books are all free :^) if you want to pirate something, go for lipmann's book, although i think you should learn C before C++ but who am i to say anything right?
>>58715284
Create a map where the keys are letters and the values are arrays of "alteration" characters.
As you iterate over the string, index the map with each character, generate a random number between 0 and array.size() -1, and retrieve the character at that index in the array. Then set string character to be equal to the character you just retrieved.
>>58715983
Really? Is C sharp lower level than C++?
>>58716055
No, but C is. besides Assembly, C will be the lowest level language one would use.
>>58716055
Anyway, I gotta go.
if you want to learn C (what I think you should do before C++) try searching for K&R C Book, it's the start of C, everyone should at least once at it imo.
also, pic of my book :^) see ya
>>58716232
Thanks a lot guy, I'll check it out!
>>58715284
Is there meant to be a space between the words? On mobile so can't tell.
>>58715284
The C way:
Make new storage location
Create counter at 0
For every character in input copy over _, char, _... Incrementing counter each time
//Java way
String input = "bdog";
String output = "";
For(int i = 0; i < input.length(); i++) {
Output += ('_' + input.charAt(i) + '_');
I'm on the toilet so this might not be syntactically correct