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. qsort problem

qsort problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++tutorial
5 Posts 4 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

    can anyone help me on how to use the stl qsort and if possible give me examples. i am try to use qsort so that i can sort out values from smaller value to higher values. how do i do that? anyways, thank you very much... Thank you very much, John :-D Aloha from Hawaii :-)

    M A 2 Replies Last reply
    0
    • J John Cruz

      can anyone help me on how to use the stl qsort and if possible give me examples. i am try to use qsort so that i can sort out values from smaller value to higher values. how do i do that? anyways, thank you very much... Thank you very much, John :-D Aloha from Hawaii :-)

      M Offline
      M Offline
      Maxwell Chen
      wrote on last edited by
      #2

      int MySort( const void *arg1, const void *arg2 )
      {
      /* Compare all of both strings: */
      return *(char*)arg1 - *(char*)arg2;
      }

      void main()
      {
      char sText[10];

      strcpy(sText, "ASDFGHJKL");
      qsort(sText, strlen(sText), sizeof(char), MySort);

      printf(sText);
      printf("\n");
      }

      Maxwell Chen People say "No news is good news". Then, no bug is good bug!?

      1 Reply Last reply
      0
      • J John Cruz

        can anyone help me on how to use the stl qsort and if possible give me examples. i am try to use qsort so that i can sort out values from smaller value to higher values. how do i do that? anyways, thank you very much... Thank you very much, John :-D Aloha from Hawaii :-)

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

        // Next time just use msdn.X| Example /* QSORT.C: This program reads the command-line * parameters and uses qsort to sort them. It * then displays the sorted arguments. */ #include #include #include int compare( const void *arg1, const void *arg2 ); void main( int argc, char **argv ) { int i; /* Eliminate argv[0] from sort: */ argv++; argc--; /* Sort remaining args using Quicksort algorithm: */ qsort( (void *)argv, (size_t)argc, sizeof( char * ), compare ); /* Output sorted list: */ for( i = 0; i < argc; ++i ) printf( "%s ", argv[i] ); printf( "\n" ); } int compare( const void *arg1, const void *arg2 ) { /* Compare all of both strings: */ return _stricmp( * ( char** ) arg1, * ( char** ) arg2 ); } Output [C:\code]qsort every good boy deserves favor boy deserves every favor good X| X| X| X| X| X| X| Aizik Yair Software Engineer

        J 1 Reply Last reply
        0
        • A Aizik Yair

          // Next time just use msdn.X| Example /* QSORT.C: This program reads the command-line * parameters and uses qsort to sort them. It * then displays the sorted arguments. */ #include #include #include int compare( const void *arg1, const void *arg2 ); void main( int argc, char **argv ) { int i; /* Eliminate argv[0] from sort: */ argv++; argc--; /* Sort remaining args using Quicksort algorithm: */ qsort( (void *)argv, (size_t)argc, sizeof( char * ), compare ); /* Output sorted list: */ for( i = 0; i < argc; ++i ) printf( "%s ", argv[i] ); printf( "\n" ); } int compare( const void *arg1, const void *arg2 ) { /* Compare all of both strings: */ return _stricmp( * ( char** ) arg1, * ( char** ) arg2 ); } Output [C:\code]qsort every good boy deserves favor boy deserves every favor good X| X| X| X| X| X| X| Aizik Yair Software Engineer

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

          thank you very much for you guys help. i really appreciate it. i dont have a MSDN library so i couldnt do this problem. thank you very much again. Thank you very much, John :-D Aloha from Hawaii :-)

          M 1 Reply Last reply
          0
          • J John Cruz

            thank you very much for you guys help. i really appreciate it. i dont have a MSDN library so i couldnt do this problem. thank you very much again. Thank you very much, John :-D Aloha from Hawaii :-)

            M Offline
            M Offline
            Martin Ziacek
            wrote on last edited by
            #5

            John Cruz wrote: i dont have a MSDN library Have you seen http://msdn.microsoft.com/library ? Kind regards to 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