| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Okay, I'm a pretty new programmer, but I've decided to tackle a rather sophisticated project by myself. I've done it all by myself, with extensive debugging (only had to look at a book to figure out the ifstream business!) but I'm hung up with one slight problem.
The basic function of the code is to let the user input a word, and then, with the help of a word list, display the first word that contains all the original word's letters minus one (as in removing one letter then rearranging the remaining letters.) Example: sprite spite Then the following word is passed through the same process, yielding: pits tip it i (or other words that also fit the criteria) The problem I have is that my program only runs through the word list once. So if the word list is: i it tip pits spite Then if you type in sprite, only spite will come up, and then the program will end (because it reaches the end of the word list). The reason for loops and while loops don't work is because I'm running an ifstream (newfile) and so the next iteration of the loop, newfile won't start at the top again. The only way I know to get the ifstream to start anew is to use another stream (as in typing "ifstream newfile2"). I'm sure there is a very easy solution, but this is my first true venture into file streams. Hopefully one of you can help me. PHP Code:
This is my word list, just for reference: arsenic carneys shroud yearns earns test gopher near word ran blah an i a In case the code isn't clear (sorry), I'll try to describe it better for you. Thanks for the help (and yes, this is for my own random nerdy purposes, it isn't for homework...) |
|
#2
|
|||
|
|||
|
In addition
I also realized that my "anagram finder" function potentially messes up when a letter is repeated in a word... but never mind that, I'll try to fix it once I squash the other bug.
|
|
#3
|
||||
|
||||
|
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 280
![]() |
|
#5
|
|||
|
|||
|
Quote:
Awesome, thank you. I fixed the problem by means of vectors (which use a lot more memory, I'm assuming) but your help allows me to write much more elegant and precise code. Thanks. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Pretty new programmer with a slightly complex problem... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|