# Word unscrambling

Show 80 post(s) from this thread on one page
Page 2 of 3 First 123 Last
• 01-07-2006
pukebucket
Well the file is large so I found the largest one I could (12 charectors) but said 15 to be sure. Sorry if this complicates things I didn't realise how important it is. I though it was like when you declare integers larger then you need to prevent overflows.

No we haven't studied letter frequency counter.

Thanks again.
• 01-07-2006
treenef
The reason why the length of the largest word to be unscrambled is important is due to the time complexity problem.

If you are using a brute force, i.e a permutation generator then a word with 12 letters in it would take a long time to solve.

Whereas, with a letter frequency counter can solve any word of any length.
• 01-07-2006
pukebucket
I see. So this means that my program will take along time to solve all ten?
• 01-07-2006
Queatrix
>> I see. So this means that my program will take along time to solve all ten?

That totaly depends.
• 01-07-2006
treenef
Yes, since if you use a permutation generator, then by its very nature you are using a brute force algorithm.

The concept of Letter Frequency counting is explained here:

http://www.codeproject.com/cpp/Jumble.asp

Which is initially where I got my idea to create an efficient word unscrambling utility.
• 01-07-2006
pukebucket
Ok. From one of your previous posts, you said to use

Code:

``` char word[MAX_WORD_SIZE][FILE_SIZE]; ifstream b_file; int i; for(i =0; i < FILE_SIZE; i++) b_file.in >> word[i];```
This is what I think each line means.

First line - Declare a char variable with the size of the largest word and the size of the file with the unscrambled words (i think)

second line - Open the unscramble file
third line - declare i as an integer variable
fourth line - Set i as o, as long as i is smaller then the file size, increase i by 1 each loop
fifth - Not sure. I think it sets the variable "word" to read the next string every loop. Is that right?

• 01-07-2006
treenef
Quote:

char word[MAX_WORD_SIZE][FILE_SIZE];
Do you have to use char arrays or string literals?

***If you have any problems post them here. I've done this before.

What I'd recommend is you read that link and think about a solution to your problem. When you have given it enough thought. Come back here.

Reading files in and out is not a problem. Worry about that later.
• 01-07-2006
pukebucket
Thank you so much :D This page looks very useful. He didn't specify how to do it, he just told us to do how ever we want :S

I'll do as you said and come back if I need more help. Once again, thank you so much it really is alot to me.
• 01-07-2006
pukebucket
I've run into a problem. At

Code:

```for (vai = all->begin(); vai != all->end(); vai++, cnt++)                        cout << cnt + 1 << " " << *vai << endl;                        char *strcpy ( char ans, const char *vai );                            ofstream a_file ( "answer.txt", ios::app ); a_file<< *vai <<","; a_file.close();```
it messes up. I tried to make it write the answers to the text file, but it always ends up being squares. I think it's becuase it's writing the memory address to the file so I tried writing vai without the asterix. But it wont compile. Does anyone know why?
• 01-07-2006
treenef
Just hang on a minute there.

Don't use the code from my link. It's perhaps a little too complicated for you anyway.

What I wanted you to do was actually read the concept behind a letter frequency counter.

Here's what you need to think about.

Let's say I give you a word:-

Code:

`treenef`
I want you to write a program which will spits out the letter frequency count for a specific word.

So...
Code:

```t = 1 r = 1 e =3 n =1 f  =1```
And as I've said before don't worry about file input/output until we've finished this.
• 01-07-2006
pukebucket
No wait, I didn't copy it. I read the whole thing, and got an understanding of it and then tried to make his one do what my one has to do. His one couldn't write it to a file. I am not going to use his one trust me, my tutor would notice :D and I would learn nothing from it. I simply want to know how it would write to a file.
• 01-07-2006
treenef
Good, don't use that code.

I said worry about file input/output later...

http://www.cprogramming.com/tutorial/lesson10.html
• 01-07-2006
pukebucket
Quote:

Originally Posted by treenef
Good, don't use that code.

I said worry about file input/output later...

http://www.cprogramming.com/tutorial/lesson10.html

• 01-07-2006
treenef
```#include <iostream> using namespace std; int main() {     char array[100]="treenef";         cout<<array[0];     cout<<array[1];         //letter count prog goes here         cin.get();     return 0; }```