943,650 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4762
  • C RSS
Apr 1st, 2004
0

character processing

Expand Post »
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
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
machakwa is offline Offline
2 posts
since Apr 2004
Apr 1st, 2004
1

Re: character processing

Quote originally posted by machakwa ...
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?
Reputation Points: 12
Solved Threads: 0
Newbie Poster
Creator is offline Offline
5 posts
since Mar 2004
Apr 1st, 2004
1

Re: character processing

So, for in C? Do you use *Shift+S* or just s?
Yzk
Reputation Points: 82
Solved Threads: 14
Posting Whiz
Yzk is offline Offline
380 posts
since Mar 2004
Apr 1st, 2004
0

Re: character processing

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.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Apr 1st, 2004
0

Re: character processing

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 ?
Reputation Points: 11
Solved Threads: 0
Newbie Poster
machakwa is offline Offline
2 posts
since Apr 2004
Apr 1st, 2004
0

Re: character processing

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.
Reputation Points: 28
Solved Threads: 9
Posting Whiz in Training
BountyX is offline Offline
222 posts
since Mar 2004
Apr 2nd, 2004
0

Re: character processing

Quote originally posted by machakwa ...
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.
Reputation Points: 12
Solved Threads: 0
Newbie Poster
Creator is offline Offline
5 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Library compatibility problem?
Next Thread in C Forum Timeline: Screenshot





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC