LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2003, 09:47 PM   #1
simbo
LQ Newbie
 
Registered: Apr 2003
Posts: 17

Rep: Reputation: 0
*comparison in C


Hi all,
I'm trying to write a bottom-up sort function, it has the same interface as qsort() in stdlib.h like that one
void qsort(type *base,int nel,int width,int (*compar)(type *,type *))

and I have read my data into an array of structs that have two members a char * and an int . My comparison functions work fie when I use qsort(), but because I have to write my own sort function(which has same interface as above), I can't seem to pass the correct arguments to the comparison function inside my sorting function, my comparison function has this interface
int intcompare( const void *i, const void *j)
int comparestr( const void *i, const void *j)
So in my sorting function I don't call either, rather I call compar, because my comparisons depend on whether the user wants to sort by int's or alphabetically. So I want to be able to pass to the comparison function aux[i] and aux[j] which are of type NODE which is my struct.

If you've read this far I appreciate your help. Thanks in advance
 
Old 04-22-2003, 10:37 PM   #2
fatman
Member
 
Registered: Mar 2003
Location: PA
Distribution: Ubuntu (x2)
Posts: 158

Rep: Reputation: 30
Did you include stdlib.h in your code?

If you did you may have problems since overloading is not supported by C.
 
Old 04-22-2003, 11:05 PM   #3
simbo
LQ Newbie
 
Registered: Apr 2003
Posts: 17

Original Poster
Rep: Reputation: 0
I did include stdlib.h, but I don't think that is the problem because my problem is how do i pass in the NODE arg[i] and NODE arg[j] arguments into the specified comparison function
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
comparison izza_azhar Programming 4 01-19-2005 11:57 PM
Comparison introuble Programming 1 01-18-2005 02:57 PM
OS Speed Comparison Tarential Linux - General 4 01-20-2004 09:02 PM
Comparison halobungie Linux - Newbie 4 08-10-2003 03:55 PM
Not your standard WM comparison. adz Linux - Software 3 07-27-2003 11:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration