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

Forum statistics

Threads
474,262
Messages
2,571,059
Members
48,769
Latest member
Clifft

Latest Threads

Top