in a part of my project i need to print letter frequencies to the screen. it's some kind of deciphering, changing letters according to the frequency. but i couldnt find a way to print them.
ty for your help
in a part of my project i need to print letter frequencies to the screen. it's some kind of deciphering, changing letters according to the frequency. but i couldnt find a way to print them.
ty for your help
So you know how to count them but not print them? Have you tried printf()?
If you understand what you're doing, you're not learning anything.
Try:
Then count[0] represents how many a's there are, count[1] is how many b's, and so on. You'll have to change it a bit to handle upper and lower case, punctuation, etc...whatever might be in the string.Code:char str[] = "ioawjoiajoiwehfaiohfiasjdfaoijfoiawhuahgowienvawecm"; int count[26] = { 0 }; int i; for(i = 0;str[i];++i) count[str[i] - '0']++;
EDIT: Another possibility is to just make the count[] array 128 elements big (256 if str holds unsigned chars) and then just do:
Code:count[str[i]]++;
Last edited by itsme86; 07-31-2006 at 11:27 AM.
If you understand what you're doing, you're not learning anything.
huffman encoding per chance?
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
should beCode:str[i] - '0'
Code:str[i] - 'a'
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
Oops...thanks for catching that.Originally Posted by XSquared
If you understand what you're doing, you're not learning anything.
No problem. I don't provide any useful input, I'm just a pedantic ass.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
Your compiler has never failed me.
$ xsquared foo.c -o foo -Wall -ansi -pedantic-ass
Except now that I think of it, it would really help if you made a version where the errors weren't displayed in the form of a short riddle.
Last edited by whiteflags; 07-31-2006 at 11:43 AM.
thanks for help. now i can continue on my project but,
i need to use clrscr(); can i just copy paste conio.h into dev-c++ library files?
Whoopah! FAQ to the rescue!
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
aight everything works fine. but, every time i change letters frequency numbers doubles. example output:
blablasometext
---------------
b=2
l=2...
change: b
new: a
-clrscr-
blablasometext
a--a----------
b=4
l=4..
Code:else{ i=0; for (i=0;n_msg2[i]!='\0';i++){ if(n_msg2[i]=='\n'){ n_msg2[i]='\n';} else{ n_msg2[i]='-';}} do{ clrscr(); printf("\n\n%s",msg2); printf("\n\n%s",n_msg2); printf("\n\n\n\nLETTER FREQUENCY\n"); for (l_freq=0;msg2[l_freq];++l_freq){ freq[msg2[l_freq]-'a']++; } letter='a'; do{ printf("%c - %d\n",letter,freq[l_counter]); l_counter++; letter++; }while (l_counter!=26); printf("\nEnter the letter to change - 0 to Quit: "); change=getch(); printf("\nEnter the new letter - 0 to Quit: "); n_letter=getch(); i=0; do{ if(msg2[i]!=change){ i++; } else{ n_msg2[i]=n_letter; i++; } }while(msg2[i]!='\0'); }while(change!='0'); }}
Doesn't look like you're setting the frequency count back to 0 between loop iterations...
If you understand what you're doing, you're not learning anything.
Next time, try posting your code.
Quzah.
Hope is the first step on the road to disappointment.