character processing

Reply

Join Date: Apr 2004
Posts: 2
Reputation: machakwa is an unknown quantity at this point 
Solved Threads: 0
machakwa machakwa is offline Offline
Newbie Poster

character processing

 
1
  #1
Apr 1st, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 5
Reputation: Creator is an unknown quantity at this point 
Solved Threads: 0
Creator Creator is offline Offline
Newbie Poster

Re: character processing

 
1
  #2
Apr 1st, 2004
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 381
Reputation: Yzk is an unknown quantity at this point 
Solved Threads: 14
Yzk's Avatar
Yzk Yzk is offline Offline
Posting Whiz

Re: character processing

 
1
  #3
Apr 1st, 2004
So, for in C? Do you use *Shift+S* or just s?
- Yzk
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 129
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: character processing

 
0
  #4
Apr 1st, 2004
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.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 2
Reputation: machakwa is an unknown quantity at this point 
Solved Threads: 0
machakwa machakwa is offline Offline
Newbie Poster

Re: character processing

 
0
  #5
Apr 1st, 2004
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 ?
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 219
Reputation: BountyX is an unknown quantity at this point 
Solved Threads: 8
BountyX's Avatar
BountyX BountyX is offline Offline
Code Guru

Re: character processing

 
0
  #6
Apr 1st, 2004
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.
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 5
Reputation: Creator is an unknown quantity at this point 
Solved Threads: 0
Creator Creator is offline Offline
Newbie Poster

Re: character processing

 
0
  #7
Apr 2nd, 2004
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC