| | |
Word Descrambler....
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I am a beginner at C++, (thought not really to programming in general)...........................
and decided to challenge myself to write something: A descrambler...........
I know what I need to do.
I need to:
i know how to open the files, and get their contents...
what i don't know is how to find how many certain letters are in a word, and how to find the length of the word(actually, I have some idea,...just using a loop)
thanks,
Kodiak( A n00by C++ programmer)
and decided to challenge myself to write something: A descrambler...........
I know what I need to do.
I need to:
C++ Syntax (Toggle Plain Text)
(any code is pseudocode) open scrambled words file open the wordlist :loop get scrambled words get wordlist compare length of a scrambled word to all of the wordlist words if(length of two words is the same) compare amount of each letter;<-----compare how many a's, b's, c's, etc. if(amount of each letter is the same) print unscrambled word from wordlist to a file goto loop(when whitespace detected) The unscrambled wordlist is in a file, and every word is on a new line. could i somehow detect the whitespace, and it switch down and restart the loop?
i know how to open the files, and get their contents...
what i don't know is how to find how many certain letters are in a word, and how to find the length of the word(actually, I have some idea,...just using a loop)
thanks,
Kodiak( A n00by C++ programmer)
FIXED!
EDIT: because i only have so long to edit i may have to double post to get some more info in thurr.
C++ Syntax (Toggle Plain Text)
//get the length of a string using the sexually transmitted library #include <iostream> #include <cstdlib> using namespace std; int main() { string foo = "mystring"; cout << foo.length(); }
EDIT: because i only have so long to edit i may have to double post to get some more info in thurr.
Last edited by Killer_Typo; Jul 7th, 2007 at 11:03 pm.
Dont forget to spread the reputation to those that deserve!
•
•
•
•
thanks alot!!! now i just need a way to compare letters...!! thanks!!!!!!!!!!!!
C++ Syntax (Toggle Plain Text)
string foo = "some string of some length"; for each ( char letter in foo ) { cout << letter << endl; }
i have the logic already written up for counting letters but you should play around with it some more before i hand the code over :-D
Dont forget to spread the reputation to those that deserve!
•
•
•
•
thanks, but that code didn't work.... maybe explain to me how to use it??
didnt work as in it wouldnt compile?
or didnt work as in it wouldnt count the letters?
make sure you are including the right files to use strings from the standard type libraries
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> using namespace std; int main() { string mystring = "hello world"; for each (char letter in mystring) { cout << letter << endl; } }
C++ Syntax (Toggle Plain Text)
h e l l o w o r l d
Dont forget to spread the reputation to those that deserve!
AFAIK, thats not standard C++. There is no 'for...each' construct in C++. Its C++/CLI.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
well damn my compiler for giving me access to for each.
let's write a while statement then!
let's write a while statement then!
C++ Syntax (Toggle Plain Text)
string foo = "super duper long string of wooorrrdddsss"; int c = 0; while ( c < foo.length() ) { cout << foo[c]; c++; }
Last edited by Killer_Typo; Jul 8th, 2007 at 2:53 am.
Dont forget to spread the reputation to those that deserve!
Sorry I wasn't more specific...
I use dev C++(which I love) , and it wasn't compiling.
I then tried to compile it in visual c++ and it worked fine, but I dont think you understand exactly what I need, it's my fault, I explained my problem badly.
I need some thing that will read the word "kodiak"
and spit out:
6 characters long.
uses "k" 2 times.
uses "o" 1 time.
uses "d" 1 time.
uses "i" 1 time.
uses "a" 1 time.
...........................................If the code you posted does do this, then I'm sorry....
I don't need you to write all of my code for me, i can get the file to go to an array, and compare them, and finally write the answers to a file, etc.
I just need code that will tell me what i have posted above.
I am very grateful for you helping me become a better C++ programmer,
Kodiak
I use dev C++(which I love) , and it wasn't compiling.
I then tried to compile it in visual c++ and it worked fine, but I dont think you understand exactly what I need, it's my fault, I explained my problem badly.
I need some thing that will read the word "kodiak"
and spit out:
6 characters long.
uses "k" 2 times.
uses "o" 1 time.
uses "d" 1 time.
uses "i" 1 time.
uses "a" 1 time.
...........................................If the code you posted does do this, then I'm sorry....
I don't need you to write all of my code for me, i can get the file to go to an array, and compare them, and finally write the answers to a file, etc.
I just need code that will tell me what i have posted above.
I am very grateful for you helping me become a better C++ programmer,
Kodiak
•
•
•
•
Sorry I wasn't more specific...
I use dev C++(which I love) , and it wasn't compiling.
I then tried to compile it in visual c++ and it worked fine, but I dont think you understand exactly what I need, it's my fault, I explained my problem badly.
I need some thing that will read the word "kodiak"
and spit out:
6 characters long.
uses "k" 2 times.
uses "o" 1 time.
uses "d" 1 time.
uses "i" 1 time.
uses "a" 1 time.
...........................................If the code you posted does do this, then I'm sorry....
I don't need you to write all of my code for me, i can get the file to go to an array, and compare them, and finally write the answers to a file, etc.
I just need code that will tell me what i have posted above.
I am very grateful for you helping me become a better C++ programmer,
Kodiak
so if we have a statement to itterate through all of the letters in the word it is now about counting each of the letters as they appear

case/switch will work for this
psuedo code:
while counting through each letter in the word
check to see what letter you are
check to see if you are a letter (not a space or symbol)
if you are a letter determin which letter you are
once i have determined the letter add you to my letter counter
etc...do this for each letter in the word
Dont forget to spread the reputation to those that deserve!
![]() |
Other Threads in the C++ Forum
- Previous Thread: Help Please - with String Manipulation
- Next Thread: using forks
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






