#### Archived

This topic is now archived and is closed to further replies.

# SOS!!! I need some help, I have 3 days :\

This topic is 5488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If I have a structure to hold products. struct Products_{ char name[70]; //product name short ID; // ID of the product float price; // Price of the program }; and another to hold the source of the products, cause each source holds diferents products like: // Coke.product[03].ID; struct Source_{ struct Products_ Product[700]; // hold 700 products short ID; }; Source_ Source[7]; // now we have 7 sources (companies) and each one has 700 products NOW MY DOUBT:============================ How to sort by: - ID - NAME And how to use dates here? and sort by date? Please I need some answer, It''s my job in game :\ Rodrigo Dietze

##### Share on other sites
This is regular C, eh? Well, I was always a fan of qsort for sorting. First you create a comparison function:

int product_sorter_name_ascending(const void *v1, const void *v2){     Products_* p1 = (Products_*)v1;     Products_* p2 = (Products_*)v2;     // Change to strcmp for case-comparison     return stricmp(p1->name, p2->name);}

Then you can use qsort on each source:

for(int i = 0; i < 7; i++){   qsort(Source[i].Product,700,sizeof(Products_),product_sorter_name_ascending);}

And that''s the gist of it. You can modify your comparison function for descending order, or change it to check ID''s as well. I don''t see dates anywhere so I don''t know what format those are in.

##### Share on other sites
Well you could consider using STL, or you can just google search and use a tried-and-true search algorithm.

-- Steve --

##### Share on other sites
Oh!! Some good souls!!

Thanks a lot!!

I''m very grateful

I could lose my job if I didn''t that. :\

Thanks

Rodrigo Dietze

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 39
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631717
• Total Posts
3001878
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!