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

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?

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

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.

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 ?

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.