Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8988451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:00:51+00:00 2026-06-15T22:00:51+00:00

I have used the following code to sort files in alphabetical order and it

  • 0

I have used the following code to sort files in alphabetical order and it sorts the files as shown in the figure:

for(int i = 0;i < maxcnt;i++) 
{
    for(int j = i+1;j < maxcnt;j++)
    {           
        if(strcmp(Array[i],Array[j]) > 0)
        {            
            strcpy(temp,Array[i]);      
            strcpy(Array[i],Array[j]);      
            strcpy(Array[j],temp);    
        }    
    } 
}

enter image description here

But I need to sort it as order seen in Windows explorer

enter image description here

How to sort like this way? Please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:00:51+00:00Added an answer on June 15, 2026 at 10:00 pm

    For a C answer, the following is a replacement for strcasecmp(). This function recurses to handle strings that contain alternating numeric and non-numeric substrings. You can use it with qsort():

    int strcasecmp_withNumbers(const void *void_a, const void *void_b) {
       const char *a = void_a;
       const char *b = void_b;
    
       if (!a || !b) { // if one doesn't exist, other wins by default
          return a ? 1 : b ? -1 : 0;
       }
       if (isdigit(*a) && isdigit(*b)) { // if both start with numbers
          char *remainderA;
          char *remainderB;
          long valA = strtol(a, &remainderA, 10);
          long valB = strtol(b, &remainderB, 10);
          if (valA != valB)
             return valA - valB;
          // if you wish 7 == 007, comment out the next two lines
          else if (remainderB - b != remainderA - a) // equal with diff lengths
             return (remainderB - b) - (remainderA - a); // set 007 before 7
          else // if numerical parts equal, recurse
             return strcasecmp_withNumbers(remainderA, remainderB);
       }
       if (isdigit(*a) || isdigit(*b)) { // if just one is a number
          return isdigit(*a) ? -1 : 1; // numbers always come first
       }
       while (*a && *b) { // non-numeric characters
          if (isdigit(*a) || isdigit(*b))
             return strcasecmp_withNumbers(a, b); // recurse
          if (tolower(*a) != tolower(*b))
             return tolower(*a) - tolower(*b);
          a++;
          b++;
       }
       return *a ? 1 : *b ? -1 : 0;
    }
    

    Notes:

    • Windows needs stricmp() rather than the Unix equivalent strcasecmp().
    • The above code will (obviously) give incorrect results if the numbers are really big.
    • Leading zeros are ignored here. In my area, this is a feature, not a bug: we usually want UAL0123 to match UAL123. But this may or may not be what you require.
    • See also Sort on a string that may contain a number and How to implement a natural sort algorithm in c++?, although the answers there, or in their links, are certainly long and rambling compared with the above code, by about a factor of at least four.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code I'd like to be used to custom sort my
I have used following code to convert string to json and parse it. String
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have used following code to create a simple PDF file. It executes fine
I have used the following code to pick up an image from phone's gallery:
I have used the following code in a number of applications to load .DLL
i have used the following code in .htaccess Options +FollowSymlinks RewriteEngine On RewriteBase /
I have used the following code to set cookie and then redirect. String level=(String)
I have used the following code to get the document root. $path = get_file_dir();
Up to this point, I have used the following code to restrict the application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.