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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:39:33+00:00 2026-05-23T08:39:33+00:00

When I run add cards using add_card, on the 7th card it is supposed

  • 0

When I run add cards using add_card, on the 7th card it is supposed to sort all of the cards. But when I run this I get a semi-ordered result.

>> require 'ext/straight_count' #=> true                                                                                          >> s = EV::StraightCount.new; s.add_card(5,0); s.add_card(8,1); s.add_card(12,2); s.add_card(14,3); s.add_card(12,4); s.add_card(3,5); s.add_card(5,6)
card: 12
card: 5
card: 12
card: 14
card: 8
card: 5
card: 3

I don’t think there is a problem with NUM2INT, because when I print the array back unordered, it comes out as expected.

straight.h

int *pCards, *pSortedCards;
int cCards[NUM_CARDS], cSortedCards[NUM_CARDS];

straight.c

void Init_straight() 
{
    pCards = &cCards[0];
}

static VALUE 
add_card(VALUE self, int rCardValue, int rCardIndex)  
{
    *(pCards + NUM2INT(rCardIndex)) = NUM2INT(rCardValue);
    if (NUM2INT(rCardIndex) == 6)
        check_for_straight();

    return Qnil;
}

check_for_straight()
{
    sort_by_value(pCards);
}

card_sort.c

int compare_card_values (const void *a, const void *b) 
{
    const double *da = (const double *) a;
    const double *db = (const double *) b;
    return (*da > *db) - (*da < *db);
}

void sort_by_value(int *pCards) 
{
    qsort(pCards, NUM_CARDS, sizeof(pCards[0]), compare_card_values);
}
  • 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-23T08:39:34+00:00Added an answer on May 23, 2026 at 8:39 am

    You’re casting the card values to double in compare_card_values even though the array contains int. Try this instead:

    int compare_card_values (const void *a, const void *b) 
    {
        const int *da = (const int *) a;
        const int *db = (const int *) b;
        return (*da > *db) - (*da < *db);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason I can't get this script to run when I add the
I'm attempting to add a mirgration before I run my project. I get the
I mainly followed this thread: How do you add files to a jar using
I am trying to get image from URL to ImageView I'm curently using this
I need run ts:reindex when smth add in model or destroy from model. How
If I add a new object and go .save() then run a select, the
Is there a way to add build steps to a run configuration in Eclipse?
In iphone I add twitter framework. When I am run that project it give
When I run Roles.GetRolesForUser(username) the roles are returned correctly, however if I add a
I've been trying to run the following command on PowerShell: netsh http add sslcert

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.