954,132 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

character processing

Could anyone tell me how me to count the frequency of character appear
in a paragraphy using c program

For example, SHE IS GIRL
S appear two time
so we output S
thanks

machakwa
Newbie Poster
2 posts since Apr 2004
Reputation Points: 11
Solved Threads: 0
 
Could anyone tell me how me to count the frequency of character appear in a paragraphy using c program For example, SHE IS GIRL S appear two time so we output S thanks

I'm not quite sure about what you mean. What exactly do you want to output?

Creator
Newbie Poster
5 posts since Mar 2004
Reputation Points: 12
Solved Threads: 0
 

So, for in C? Do you use *Shift+S* or just s?

Yzk
Posting Whiz
380 posts since Mar 2004
Reputation Points: 82
Solved Threads: 14
 

Well, suppose you have the string "GIRL". A string is an array of characters. Store the letter you want to search for as a character. So what you will have to do is start at the beginning of the array, and recursively traverse it one character at a time. We look at the first character. Is it equal to our search character? If yes, increment our counter. Move to the second element (character) in the array. Check if it is a match. Then move to the next character, etc.

cscgal
The Queen of DaniWeb
Administrator
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229
 

can i use if statement to count the frequency

for example
c=getchar()
if c='a' && 'A'
cnta++
.....to if c=z...

and one more question

when more than one characters have the same frequencies
how can i take out the earlier one ?

machakwa
Newbie Poster
2 posts since Apr 2004
Reputation Points: 11
Solved Threads: 0
 

i think you mean || (or) instead of && (and), other than that what you posted should work.

As for the other ? , If you know the length of the file, you can stop immedietly once a certian frequency has been found.

BountyX
Posting Whiz in Training
230 posts since Mar 2004
Reputation Points: 28
Solved Threads: 9
 
can i use if statement to count the frequency for example c=getchar() if c='a' && 'A' cnta++ .....to if c=z... and one more question when more than one characters have the same frequencies how can i take out the earlier one ?

That won't neccesarily work. You're going to need to make a loop and a lot more code to actually search a string. If you are talking about big strings you might want to search for a substring with strstr(). Then get the position of the character you are searching for by finding the difference in the subtring and the string itself. After that, you can use a specific tallying method to loop through that again but skip over the first appearance and go to the third, then fourth, etc... Until the end.

Creator
Newbie Poster
5 posts since Mar 2004
Reputation Points: 12
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You