0
Anyone
Find how many times character a, b, c and d are presented in a sentence entered by a person
8 Answers
+ 5
Are you counting the alphabets frequency only? does letter case matter?
My idea for alphabets counter only, is to use a 2D array of `unsigned int` preloaded with zeroes. Use the first row to store uppercase letters frequency, and the second row to store lower case letters frequency. Each row will have 26 elements (number of alphabets).
You run a loop to iterate the C-string and increments the respective element value.
for each letter in string
if letter is an alphabet
if letter in uppercase form
update array[0][ letter - 'A' ]
else
update array[1][ letter - 'a' ]
+ 4
Sunday,
I would assist you get through this, but I wanna see your tryout code first. Don't you want to give it a try?
You can share your code link here, following this guide ...
https://www.sololearn.com/post/75089/?ref=app
+ 4
I like Ipang idea of a 2 dimensional array to store 52 character frequencies.
You could use a alphabet validation similar to the camelCase challenge.
for (i=0,j=0;i<=N;i++,j++)
if( (*(iw+i)=='_')
|| (*(iw+i)>='a')
&& (*(iw+i)<='z') ) {
*(ow+j)=*(iw+i);
}
else if ( (*(iw+i)>='A')
&& (*(iw+i)<='Z') ) {
if (i!=0){
*(ow+j)='_';
j++;
}
*(ow+j)=(char)(*(iw+i)+32);
}
Then maybe a switch case to sort and store the char count into the 2D array.
Good luck Sunday , please share your attempt!
+ 2
Sunday,
Just sketch a code with what you already learned this far, the community helps with suggestions or recommendations after they see what and where it was needed.
Maybe start by making the frequency counter array, and setting up a loop to iterate the input string.
Don't be afraid to make mistakes, everybody does, while learning, it's fine.
+ 2
Ipang ,HungryTradie ,Nursaid Muratov I have completed the code and it run fairly good š, thank you thank you all for helping me
+ 1
Ipang Letter case does not matter, assuming the user will enter sentence in lower case alphabet only
And, sorry can you write that code please cause I'm confused with your explanation.
+ 1
Ipang actually, I have no Idea what to start with
0
Hello/Hi/Salut/ŠŠ ŠŠŠŠ¢/Š”ŠŠŠŠ/Š”ÓŠ»ŠµŠ¼/Ohayo