Hi! I'm trying to create a program that reads a file and pulls the first letter of each word in a string (a sentence of nine words) that will then spell a different word (nine letter word). So far, I've only been able to access the first letter of the first word. I think I need to use strcat to put the nine letters together, but I'm not sure how? I've looked online, etc., but still don't understand. Here's what I have so far:
You're not collecting the first letters of the words input anywhere. You have a string called "word" which would be perfect for that.
Before your loop, clear word to make sure it's empty. Then, after your loop, concatenate each letter that you extract onto word. Finally, after your loop, write out the contents of word.
Hi,
Thank you so much for replying. For that "word" string, I was trying to collect the letters by using getline (word " "), but that wasn't working... I've looked up how to use concatenate, but I can't seem to get how to do that either. It's like??
Concatenation with strings is pretty easy; part of the string class includes a concatenation operator "+".
You clear the variable word (which I've renamed wordOut below) just to make sure that it doesn't have any (unintended) data in it already. This may not be necessary, but in general it's a good idea to initialize your variables in C++.
Thank you. This looks much better than what I was going to do. When I run it, though, I still only get the first letter of the first word, twice. Do I need strcat anywhere at the end or anything? Thanks again!
I get the entire message now. Thanks! I'm not sure how to get rid of the extra letter on the message. When I run it, my output looks like this:
G
E
O
G
R
A
P
H
Y
Y
GEOGRAPHYY
Sorry for all the questions. Thanks for all your help!
Thank you so much! The extra Y is still on there, but the individual letters are gone now and it just reads the word GEOGRAPHYY. Stupid question, but there's a period at the end of the sentence in the data file, is that why the extra letter on the end? Thank you! I really appreciate your help!
Just checked, and "Yellow" isn't in there twice. It's probably just my computer or something. I'm using this PUTTY system for the program. Not sure about how good PUTTY is. Perhaps I'll try and run the program on a different computer? Thanks again! You've been so kind and helpful!
No problem at all...keep plugging away. And yeah, try compiling your program with a different compiler, just for fun. Let me know if you want more help.