[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I'm trying to make a program that loops through all of the

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 31
Thread images: 5

File: 148496999279312.jpg (26KB, 476x420px) Image search: [Google]
148496999279312.jpg
26KB, 476x420px
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?
>>
>>58715284
def 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?
>>
File: 1481724546269.jpg (98KB, 573x768px) Image search: [Google]
1481724546269.jpg
98KB, 573x768px
>>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 be
 for (words; i = 0; i < size; ++i) 

?
>>
File: 1478712586416.gif (188KB, 500x375px) Image search: [Google]
1478712586416.gif
188KB, 500x375px
>>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++?
>>
File: 1484007366756.jpg (15KB, 480x306px) Image search: [Google]
1484007366756.jpg
15KB, 480x306px
>>58716055
No, but C is. besides Assembly, C will be the lowest level language one would use.
>>
File: eq49j21043.png (3MB, 1900x1914px) Image search: [Google]
eq49j21043.png
3MB, 1900x1914px
>>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
Thread posts: 31
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.