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

When I run get-user|get-member in powershell with the exchange add-in I noticed there is
I need to add the Run when Windows starts option to my program CintaNotes,
Ubuntu has 8 run levels (0-6 and S), I want to add the run
When I add a breakpoint and hit F5 to run in the debugger (I
in JBoss' run.bat , add: set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote - Dcom.sun.management.jmxremote.port=9987 - Dcom.sun.management.jmxremote.ssl=false - Dcom.sun.management.jmxremote.authenticate=false
Is there a way to add build steps to a run configuration in Eclipse?
I would like to add the following MIME type to a site run by
I'm trying to add items to a select drop down at run time. So
I'm wondering if its possible to add new class data members at run-time in
I always run into the same problem when creating web pages. When I add

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.