How should I sort a struct

A

Angus Comber

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
(e-mail address removed)
 
P

pete

Angus said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top