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 6705925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:27:37+00:00 2026-05-26T07:27:37+00:00

I am using the selection sort to sort a list of names from a

  • 0

I am using the selection sort to sort a list of names from a cricket team.

The sort works after first repeating a name 3 times which eliminates two other names from the array I am sorting.

Input from array (in order):

Clarke Watson Beer Copeland Haddin Harris Hughes Hussey Johnson Khawaja Lyon Marsh Pattinson Ponting Siddle Warner

Output after sorting array:

Beer Beer Beer Copeland Haddin Harris Hughes Hussey Johnson Khawaja Lyon Marsh Pattinson Ponting

Code:

void sort_names (Team_t player[]) {
    int pos;
    int min;
    int i, str_check;
    char *temp = NULL;

    for (pos = 0; pos < MAX_PLYR; pos++) {
        min = pos;

        for (i = (pos + 1); i < MAX_PLYR; i++) {
            str_check = strcmp(player[i].pname, player[min].pname);

            if (str_check < 0) {
                min = i;
            }

        }

        if (min != pos) {
            temp = player[pos].pname;
            strcpy(player[pos].pname, player[min].pname);
            strcpy(player[min].pname, temp);
        }
    }    
}
  • 1 1 Answer
  • 0 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-26T07:27:38+00:00Added an answer on May 26, 2026 at 7:27 am

    This bit of your code won’t swap entries correctly:

    temp = player[pos].pname;
    strcpy(player[pos].pname, player[min].pname);
    strcpy(player[min].pname, temp);
    

    The first line saves a pointer to the ‘pos’ player’s name to temp – not the name itself. Then the first strcpy overwrites it – it is lost. (The second strcpy merely copies the same string back to where it already was.) That’s why you see the item that would sort first sprouting up more than once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying following, 1. Get response using Ajax from the users selection which
I need to Sort Linked list using Selection sort. But I can not use
I'm using opengl's selection buffer, but i'm experiencing a trouble, the picking works perfectly
I've created a simple Outlook 2007 add-in using C# which loops through a selection
I'm using jQueryUI to create a sortable list, and the UI part works great
I have a selection for some items using a spinner widget. At the moment
Hai am using telerik wpf grid in grid selection change event am getting the
I'm using the following function that changes a calendar selection at a set time
I'm trying to determine the current paper type selection on the default printer using
I have a problem with selecting not first selector using attributeContains jQuery('div[id*=abc]:not(:first)').hide();

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.