Miek Posted November 15, 2010 Posted November 15, 2010 I've got to write a program that accepts a word from the user, assigns it to a string, and then converts it and outputs it in the ICAO format. For example, if the user types in "OCC", then the output would say "Oscar Charlie Charlie". I'm not sure how to "break apart" the string letter for letter so that I can output the appropriate word for each letter of the input. Share this post Link to post Share on other sites More sharing options...
redtigerdragon Posted November 15, 2010 Posted November 15, 2010 I've got to write a program that accepts a word from the user, assigns it to a string, and then converts it and outputs it in the ICAO format. For example, if the user types in "OCC", then the output would say "Oscar Charlie Charlie". I'm not sure how to "break apart" the string letter for letter so that I can output the appropriate word for each letter of the input. Should be able to do a for loop going through the string, like so for( int i; i < string.length(); i++) char = string; something along those lines... Share this post Link to post Share on other sites More sharing options...
Miek Posted November 15, 2010 Posted November 15, 2010 OK... When I get that to work, how can I make the program stop telling me I have a ton of uninitialized local variables? They all have to be assigned so that each letter will output the right word according to the ICAO, but they won't all necessarily be used. As in, if the user types OCC, then the program will still say that everything but "o" and "c" are uninitialized local variables. I find this question quite irritating. Share this post Link to post Share on other sites More sharing options...
rmb938 Posted November 15, 2010 Posted November 15, 2010 (edited) Well I know in java you can split a string something like string[] test = split("one two"," ") so it will give you test[0] = one and test[1] = two so there should be something like that in C++ So I found this: http://dotnetperls.com/string-split scroll down to the separating words part. That link is C# but it shouldn't be that much different Edited November 15, 2010 by rmb938 Share this post Link to post Share on other sites More sharing options...
hardnrg Posted November 15, 2010 Posted November 15, 2010 As I had to stuggle through learning to code myself, I'm not going to give you the answer, but give you the essential ideas: 1) You need to read the string one character at a time 2) The ASCII codes for letters a-z ascend in value, as do the values for A-Z (if you force cast a char to int, you get the value) 3) You can use toupper() to convert all letters to uppercase 4) Apply an offset to the ASCII value of a letter to make A equal to 0 (zero) 5) Hold all the words in a two dimensional array (an array of strings, aka an array of array of chars), assign e.g. char icao[26][]; icao[0][] = "Alpha"; icao[1][] = "Bravo"; 6) If the character being read in the string isn't a letter (e.g. space, number), decide what to do instead of string concatenation (or successive string output)... Share this post Link to post Share on other sites More sharing options...
Miek Posted November 15, 2010 Posted November 15, 2010 I haven't really done anything with arrays yet. I don't even know how to use them... Share this post Link to post Share on other sites More sharing options...
CheeseMan42 Posted November 16, 2010 Posted November 16, 2010 OK... When I get that to work, how can I make the program stop telling me I have a ton of uninitialized local variables? They all have to be assigned so that each letter will output the right word according to the ICAO, but they won't all necessarily be used. As in, if the user types OCC, then the program will still say that everything but "o" and "c" are uninitialized local variables. I find this question quite irritating. To get rid of uninitialized variables, all you have to do is initialize them. Share this post Link to post Share on other sites More sharing options...
Miek Posted November 16, 2010 Posted November 16, 2010 (edited) Someone suggested to me to use stringname.at(number++) in a loop. What about that? Also, forcing all the letters to the same case via tolower or toupper to prevent the program from getting confused? AHA! TAKE THAT, C++! I have bent the program to my whim... With some help from a fellow classmate who is a genius at this. Tomorrow, she is getting a 20oz Starbucks beverage of her choice + any food item of her choice, as she said that's what she'd like. I'd buy coffee for the people here, too, but... It's impossible. Sorry. Edited November 16, 2010 by Miek Share this post Link to post Share on other sites More sharing options...
suedenim Posted November 16, 2010 Posted November 16, 2010 Steam lets you gift games... Share this post Link to post Share on other sites More sharing options...
redtigerdragon Posted November 16, 2010 Posted November 16, 2010 Steam lets you gift games... Oh suedenim, you made me lol. You sir, have won an internets. Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now