hi.. i was wondering is it possible to find out the following
lets say i enter a string like => hello
it should tell me that how many times a alphabet is used
like if i enter "hello" it should give me the following
h=1
e=1
l=2
o=1
Printable View
hi.. i was wondering is it possible to find out the following
lets say i enter a string like => hello
it should tell me that how many times a alphabet is used
like if i enter "hello" it should give me the following
h=1
e=1
l=2
o=1
Yes, the "count the characters" (AKA count occurence of each letter in a string) assignment. Search the forums, you'll find lots of hits.
i did that, found not what i was looking for.. maybe u can write a program for the world "Hello" so i can understand it better? if so, ill be thankful
anyone who can write a simple program for the above? thanks
The idea is to make an array of char's, 26 long, and set your a[] array elements all to zero.
Now for each char in your word or sentence:
a[char]++
Welcome to distribution counting. At the end, you'll have a count of every char you've scanned:
h = 1, e= 1, l = 2, o = 1.
Very useful trick to remember.
But watch out for blanks, periods, exclamation and question marks (etc...), unless you reserve a spot for them in your array.
well can I see a program? i dont understand the theory ;\
You are quite persistent. This is 4 pages of hits. One of them on the first page is a full program. http://cboard.cprogramming.com/showt...ing+characters
rofl i never said how many times a charachter is entered :\\\\\\\\ blahhhhhhhhhhhh
for example i put in the word => POWER <=
it should tell me how much times each charachter is used.. like P is used once.. O iss used once as well etc so it should displayy
p=1
o=1
w=1
e=1
r=1
get it now? pplease wite a simple code here for any string from which i can get a idea
You start the code, and someone else will critique and help you out.
i have no idea what to put in the code, im asking u to write a simple program in C that will do it for the word hello or any other word so i can get the logic and syntax etc.. if u can help then help and if u cant help then just shut the fk up as im already ........ed off
serious people who wants to help please do and whose people who wants to flame and say bull........ like "OMFG WE R SO ELITE HERE WE DUNT DO UR HOMEWORK" wtf, this is not any homework, im just trying to learn
bye
That's not at all the reason we don't do your homework. You are supposed to learn from the homework, and you won't learn anything by copying and pasting.
You have been given an almost complete description of how you should implement it, and a link to another page.
I mean, it's not like you can't solve it in just a couple of lines or so:
--Code:#include <stdio.h>
#include <ctype.h>
int main()
{ int c[27]={ 0 },*q;char b[400],*p;
printf("Enter string:"); p = fgets(b,sizeof b,stdin);
for(;*p;p++) c[(isalpha(*p))?25-(tolower(*p)-97):26]++;
for(q=&c[25];q>=c;q--) { int x = (*q)?printf("%c: %d\n", 122-(q-c),*q):0; }
return 0;
}
Mats
lol time waster