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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:12:38+00:00 2026-06-13T09:12:38+00:00

Trying to compare voids for a sorting algorithm. I have this so far but

  • 0

Trying to compare voids for a sorting algorithm. I have this so far but it kinda defeats the purpose IMO if you cast them to ints. Is there a way to compare voids? My professor ran out of time and how were stuck scowering the web. Any help is appreciated. Thanks

int fcmp(const void *one, const void *two)
{
    if (*(int*)one > *(int*)two) return 1;
    if (*(int*)one < *(int*)two) return -1;
    return 0;
}
  • 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-06-13T09:12:39+00:00Added an answer on June 13, 2026 at 9:12 am

    This looks to be a standard comparison function used in several of the standard library functions like qsort() in which you call the function with some kind of array of data items along with the comparison function that indicates whether two elements are equal to each or or not and if not what is their collating order.

    So what the void pointer points to is kind of up to the programmer. That is the purpose of using the void pointers in the comparison function interface because the function, such as qsort(), which is calling the comparison function just wants to know what order two array elements are to go in. It does not know what the array elements are or how to do the comparison, it just knows the starting address of the array and the size of each element and how many elements are there.

    Another function from the standard library is the bsearch() function.

    So to use this you might have code like the following:
    see qsort() man page.

    typedef struct {
       int iValue;
       char  sName[10];
    } DataValue;
    
    // compare two elements of the array and indicate which one is higher
    // or lower in collating sequence or if they are equal.
    int dataComp (void *one, void *two)
    {
        return ((DataValue *)one)->iValue - ((DataValue *)two)->iValue;
    }
    
    int main (int argc, char *argv[])
    {
        DataValue myData[25];
       //.. put some data stuff in the array.
       // call qsort with the array.  specify number of elements and size of each one
       qsort (myData, sizeof(myData)/sizeof(myData[0]), sizeof(myData[0]), dataComp);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to compare these two chars but on win 32 Visual Studio 2008:
I am trying to compare two tools execution time, which I have installed in
I'm trying to compare the differences between jQuery and JavaScript in a project, but
I am trying to sort an array of strings, but it's not sorting anything....
Update1: this is all looks great but there is big problem which i have
I am trying to compare to a defined constants in C, and I have
I'm trying call qsort in Cython with a custom compare function but I don't
i am trying to compare the date but its not comparing the date like
I'm trying to md5 some file with as3corelib , but if I compare the
I have a username db table that I'm trying to connect with to compare

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.