finding repeated characters in an array

how to display the number of times a character is repeated. for ex. if

Page 1 of 1

6 Replies - 12509 Views - Last Post: 21 January 2010 - 07:51 PM Rate Topic: -----

#1 naveed2043   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-January 10

finding repeated characters in an array

Post icon  Posted 21 January 2010 - 03:48 PM

how to display the number of times a character is repeated.
for ex.
if we give input as hi how are you today?
it should display answer as
a 2
h 2
o 2
y 2





hi can any one post the answer for this program its urgent.
Is This A Good Question/Topic? 0
  • +

Replies To: finding repeated characters in an array

#2 erik.price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: finding repeated characters in an array

Posted 21 January 2010 - 03:50 PM

Nope. We won't do it for you, no matter how "urgent" it is. It isn't our fault you didn't do your assignment when you should have.

Post some code you've tried out first, then we'll help

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,233
  • Joined: 14-September 07

Re: finding repeated characters in an array

Posted 21 January 2010 - 03:58 PM

Hint: make a struct that holds the letter and the number of times it's repeated. Then create an array of them.
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • Posts: 11,222
  • Joined: 15-July 08

Re: finding repeated characters in an array

Posted 21 January 2010 - 04:00 PM

Or better yet, use a map. Use the number as a key, and the number of times it occurs as a key. That'll be fun.
Was This Post Helpful? 0
  • +
  • -

#5 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,233
  • Joined: 14-September 07

Re: finding repeated characters in an array

Posted 21 January 2010 - 04:01 PM

Was that a typo? Why would you want two keys?
Was This Post Helpful? 0
  • +
  • -

#6 smeezekitty   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 18-December 08

Re: finding repeated characters in an array

Posted 21 January 2010 - 04:15 PM

Untested code:
func(){
    int count[0xFF] ;
    memset(count, 0, 255);
    for(int i = 0;i < strlen(array);i++){
        count[array[i]]++;
    }
    for(i = 0;i < 0xFF;i++){
        if(count[i] > 1){printf("%c=%d\n", count[i], i);
    }
}


Was This Post Helpful? 0
  • +
  • -

#7 jjl   User is offline

  • Engineer
  • member icon

Reputation: 1270
  • View blog
  • Posts: 4,998
  • Joined: 09-June 09

Re: finding repeated characters in an array

Posted 21 January 2010 - 07:51 PM

following what KYA suggested. Use a struct to keep tract of letter information
struct letter
{
	char letter;
	int count;

	letter(void)
	{
		count = 0;
	}
};





I would create a vector of the structure and push each letter from the text inside. Or maybe just push the hole alphabet before hand and then loop through the input text to check for matches in characters
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1