LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 03-27-2006, 12:13 PM   #1
cdog
Member
 
Registered: Dec 2005
Posts: 65

Rep: Reputation: 15
Is there a function for this?


I'm looking for a C function to sort an array of strings in alphabetical order and not ASCII order.
 
Old 03-27-2006, 12:48 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
qsort

You supply a function that compares two elements of the array, and qsort uses it as a callback, repeatedly, until the array is sorted. Your comparison function can compare on what ever basis you wish.

--- rod.
 
Old 03-28-2006, 05:03 AM   #3
cdog
Member
 
Registered: Dec 2005
Posts: 65

Original Poster
Rep: Reputation: 15
thank you.
 
Old 03-29-2006, 12:47 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Is stable_sort only C++? If you are sorting without regard to case (as in "Adam" is the same as "adam"), stable_sort will keep them in the same order in relationship to each other. This means that if you have both "Adam" and "adam" in the same list, if "Adam" occurs before "adam" in the original list, it will still be before "adam" in the sorted list. I know for sure that qsort does not guarantee that they will stay in the same order, but I'm not sure the equivalent to stable_sort in C.
ta0kira
 
Old 03-31-2006, 04:07 AM   #5
cdog
Member
 
Registered: Dec 2005
Posts: 65

Original Poster
Rep: Reputation: 15
I think that I will make a function for this because there are few more things to cover. Thank you both.
 
  


Reply



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
function defn inside a function in C...!!! arunka Programming 1 02-05-2006 01:08 AM
Calling another function from a function using GTK geminigal Programming 4 07-11-2005 03:15 PM
what are the Hexadecimal function and ASCII function in Perl Bassam Programming 1 06-03-2004 01:44 AM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 12:21 PM

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

All times are GMT -5. The time now is 07:43 AM.

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