Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. can anyone kind enough to point out my bug here.

can anyone kind enough to point out my bug here.

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structuresquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John Cruz
    wrote on last edited by
    #1

    i am trying to use qsort so that i can sort out y from highest to lowest. can anyone help me? anyways, thank you very much. struct SPRITE { int x; int y; }; // Maximum number of sprites const int N_SPRITES = 10; // Array of sprites SPRITE sprites[N_SPRITES]; int Compare (const void *one, const void *two); /* Pre: Enter value for one and two * Post: Compares all of both strings */ int main() { int value; for (int i=0; i> value; sprites[i].y = value; } qsort(sprites, N_SPRITES, sizeof(int), Compare); for (i=0; i

    A N 2 Replies Last reply
    0
    • J John Cruz

      i am trying to use qsort so that i can sort out y from highest to lowest. can anyone help me? anyways, thank you very much. struct SPRITE { int x; int y; }; // Maximum number of sprites const int N_SPRITES = 10; // Array of sprites SPRITE sprites[N_SPRITES]; int Compare (const void *one, const void *two); /* Pre: Enter value for one and two * Post: Compares all of both strings */ int main() { int value; for (int i=0; i> value; sprites[i].y = value; } qsort(sprites, N_SPRITES, sizeof(int), Compare); for (i=0; i

      A Offline
      A Offline
      Aizik Yair
      wrote on last edited by
      #2

      for (int i=0; i // ERROR { ... } for ( int i=0 ; i < N_SPRITES ; i++ ) // GOOD { ... } Aizik Yair Software Engineer

      1 Reply Last reply
      0
      • J John Cruz

        i am trying to use qsort so that i can sort out y from highest to lowest. can anyone help me? anyways, thank you very much. struct SPRITE { int x; int y; }; // Maximum number of sprites const int N_SPRITES = 10; // Array of sprites SPRITE sprites[N_SPRITES]; int Compare (const void *one, const void *two); /* Pre: Enter value for one and two * Post: Compares all of both strings */ int main() { int value; for (int i=0; i> value; sprites[i].y = value; } qsort(sprites, N_SPRITES, sizeof(int), Compare); for (i=0; i

        N Offline
        N Offline
        Niklas L
        wrote on last edited by
        #3

        First: John Cruz wrote: qsort(sprites, N_SPRITES, sizeof(int), Compare); should be qsort(sprites, N_SPRITES, sizeof(SPRITE), Compare); Second: John Cruz wrote: int Compare (const void *one, const void *two) { return strcmp((char*)one, (char*)two); } one and two are pointing to SPRITE objects. So it should be something like: return strcmp(((SPRITE*)one).y, ((SPRITE*)two).y); that is if the y member is a char*.

        J 1 Reply Last reply
        0
        • N Niklas L

          First: John Cruz wrote: qsort(sprites, N_SPRITES, sizeof(int), Compare); should be qsort(sprites, N_SPRITES, sizeof(SPRITE), Compare); Second: John Cruz wrote: int Compare (const void *one, const void *two) { return strcmp((char*)one, (char*)two); } one and two are pointing to SPRITE objects. So it should be something like: return strcmp(((SPRITE*)one).y, ((SPRITE*)two).y); that is if the y member is a char*.

          J Offline
          J Offline
          John Cruz
          wrote on last edited by
          #4

          i got your number my first mistake fixed. but the second mistake: Niklas Lindquist wrote: one and two are pointing to SPRITE objects. So it should be something like: return strcmp(((SPRITE*)one).y, ((SPRITE*)two).y); that is if the y member is a char*. this wont compile because i am using strcmp which has needs 2 const char parameters and because y is not a member of char. does any know how to fix this thing? well anyways, thank you very much. Thank you very much, John :-D Aloha from Hawaii :-)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups