Ok. So, is the ctrie part the letter count thing?
Also, do you have msn? It would be easy to talk that way
And thanks again for the help![]()
Ok. So, is the ctrie part the letter count thing?
Also, do you have msn? It would be easy to talk that way
And thanks again for the help![]()
ok let's go back to basics:
Do you know how to loop through an array of characters?
So let's say I have an array
char array[100] = "treenef";
Code:+--+--+--+--+--+--+--+ | t|r |e |e |n |e | f| +--+--+--+--+--+--+--+ 0 1 2 3 4 5 6
to loop through each character I would do this:
Code:for (int i=0; i<7; i++) { cout<<array[i]<<endl; }
Or better yet
Code:#include <cstring> size_t len = strlen(array); for(size_t i = 0; i < len; i ++) { cout << array[i] << endl; }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
And then, instead of couting the characters, you could count them . . .
Code:#include <climits> #include <cstring> #include <cctype> unsigned charcount[UCHAR_MAX] = {0}; size_t len = strlen(array); for(size_t i = 0; i < len; i ++) { charcount[array[i]] ++; } for(int x = 0; x < UCHAR_MAX; x ++) { if(charcount[x]) { cout << '\'' << isprint(x) ? x : '-' << "': " << charcount[x] << endl; } }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Yes I understand that, It would print all 7 charactors stored in the array.
Last edited by pukebucket; 01-07-2006 at 02:47 PM.
OK, that's good.
So the word treenef...
has three 'e's
one 'f'
one 't'
etc.
Would you know how to write a program to do that?
My first post would [edit]"print all 7 charectors stored in the array"[/edit], and treenef's one would too, but not my most recent one. My previous post would print something like
Code:e: 3 f: 1 n: 1 r: 1 t: 1
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Too late.Would you know how to write a program to do that?![]()
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
I see. No I don't think I could. My tutor is looking pretty bad right now. He taught us nothing like that.
To dwk: I'm not sure that I understand your code.
Sorry to be a pain people![]()
I see...
Erm in regards to dwks code, it's probably a bit too complicated.
You need something more intuitive...
Have a look at this and see if you understand the concept behind it:
Code:#include <iostream> #include <string> using namespace std; int main() { char array[100]="treenef"; int size = strlen(array); char alphabet[50]="abcdefghijklmnopqrstuvwxyz"; int letter_count[26]; for(int i=0; i<26; i++) { letter_count[i]=0; } for(int i=0; i<size; i++) { for(int j=0; j<=26; j++) { if(array[i]==alphabet[j]) { letter_count[j]++; } } } for(int j=0; j<26; j++) { cout<<alphabet[j]<<" "<<letter_count[j]++<<endl; } cin.get(); return 0; }
Ok I'll try to explain your code to show how much I understand.
Hrm, I understand quite a bit (I think, and hope) but theres still aCode:char array[100]="treenef"; //Declares a charactor array called array, of 100 bytes and saves treenaf into it int size = strlen(array); //Declares an integer called size, Then it assigns its value as the length of the array called array char alphabet[50]="abcdefghijklmnopqrstuvwxyz"; // Declares a charactor array called alphabet, of 50 bytes. Then it saves the aphabet into it. int letter_count[26]; // Declares an integer called letter_count, consisting of 26 bytes. for(int i=0; i<26; i++) // A loop. It creates an integer called i and assigns it a value of 0. It then says that as long as i is under 26 to run the next code. The i++ makes the integer i increase by 1 each loop. { letter_count[i]=0; // Im not sure. It looks like it assigns each letter of the alphabet to 0? } for(int i=0; i<size; i++) //Another loop. Assigns integer i to 0, loops if i is under the variable size, and i increases by 1 each loop. { for(int j=0; j<=26; j++) //Another loop. Sets j to 0, loops if j is bigger or equal to 26, j increases by 1 each loop { if(array[i]==alphabet[j]) //Hrm. Another loop, if value i array is eqaul to alphabet value j then do the next code. { letter_count[j]++; //Not sure } } } for(int j=0; j<26; j++) //Same as the one above { cout<<alphabet[j]<<" "<<letter_count[j]++<<endl; // Print the alphabet value j, a space, then the letter_count j. Not sure what this means. } cin.get(); return 0; }
bit I don't quite get. Sorry about the way its layed out :S
Last edited by pukebucket; 01-07-2006 at 03:17 PM.
Yeah some of what u got is right some wrong.
Draw out a flow chart to and follow each bit with your finger.
Think about it for a day or so and then come back. I'll explain any stuff you don't understand
I've got to go now.
However, you should be able to see the reason why a letter frequency count is useful for your problem.
All have the same letter frequency count.Code:treenef, feneert, eertnef,
Ok thanks. I understand why I need it now. Thanks for all the help. If I need more I'll come and ask, as for now, I got some learning to do!
Thanks and bye people.
Thanks alot treenef, your help has been invaluable, so was everyone elses.
Last edited by pukebucket; 01-07-2006 at 04:26 PM.