Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 953855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:07:03+00:00 2026-05-16T00:07:03+00:00

This question brings me back to my college days, but since I haven’t coded

  • 0

This question brings me back to my college days, but since I haven’t coded since those days (more than 20 years ago) I am a bit rusty.

Basically I have an array of 256 elements. there might be 1 element on the array, 14 or 256. This array contains the usernames of people requesting data from the system. I am trying to count the duplicates on the list so I can give the priority to the user with most requests. So, if I have a list such as:

{john, john, paul, james, john, david, charles, charles, paul, john}

I would choose John because it appeared 4 times.
I can iterate the array and copy the elements to another and start counting but it gets complicated after a while. As I said, I am very rusty.

I am sure there is an easy way to do this. Any ideas? Code would be very helpful here.
Thank you!

EDIT:

The buffer is declared as:

static WCHAR userbuffer[150][128];

There could be up to 150 users and each username is up to 128 chars long.

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:07:04+00:00Added an answer on May 16, 2026 at 12:07 am

    Here’s how I would solve it:

    First, define a structure to hold user names and frequency counts and make an array of them with the same number of elements as your userbuffer array (150 in your example).

    struct user {
        WCHAR   name[128];
        int     count;
    } users[150];
    

    Now, loop through userbuffer and for each entry, check and see if you have an entry in users that has the same name. If you find a match, increment the count for that entry in users. If you don’t find a match, copy the user’s name from userbuffer into a blank entry in users and set that user’s count to 1.

    After you have processed the entire userbuffer array, you can use the count values from your users array to see who has the most requests. You can either iterate through it manually to find the max or use qsort.

    It’s not the most efficient algorithm, but it’s direct and doesn’t do anything too clever or fancy.

    Edit:
    To qsort the users array, you will need to define a simple function that qsort can use to sort by. For this example, something like this should work:

    static int compare_users(const void *p1, const void *p2) {
        struct user *u1 = (struct user*)p1;
        struct user *u2 = (struct user*)p2;
    
        if (u1->count > u2->count)
            return 1;
        if (u1->count < u2->count)
            return -1;
        return 0;
    }
    

    Now, you can pass this function to qsort like:

    qsort(users, 150, sizeof(struct user), compare_users);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first app. It doesn't crash the simulator just brings you back
This is pretty easy question, but I have been unable to find the solution
This may sound like a simple question, but I just cannot seem to find
I have a question very similar to this one but the answer does not
My question..not even sure if this is possible but curious from others... I have
This question is directly related to this SO question I posed about 15 minutes
This question is kind of a follow up to this question I asked a
This question is really basic. What is the performance difference between removing a UIView
This question is similar in concept to this one , except I see I
This question is about good programming practices and avoiding potential holes. I read Joshua

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.