Jump to content
  • Advertisement

Archived

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

Dietze

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!