By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,313 Members | 2,725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,313 IT Pros & Developers. It's quick & easy.

How should I sort a struct

P: n/a
Hello

I have a struct with two elements as follows:

int nNumber
char szName[100]

I want to sort szName by nNumber. Eg nNumber might be 1, 3, 6, 2 - and I
want to re-sort szName - possibly intro a new struct. What is the easiest
way for me to do this?

Angus Comber
an***@NOSPAMiteloffice.com

Nov 14 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Angus Comber wrote:

Hello

I have a struct with two elements as follows:

int nNumber
char szName[100]

I want to sort szName by nNumber.
Eg nNumber might be 1, 3, 6, 2 - and I
want to re-sort szName - possibly intro a new struct.
What is the easiest way for me to do this?


Mkae an array of compar functions, so that you can index
into them with nNumber and use qsort.

--
pete
Nov 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.