From 1e8aabad3408e339a6f0dc4ef907db519c902a4c Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 1 Jul 2010 00:23:25 -0700 Subject: [PATCH] alphabetical sort Change-Id: I4b1bb6787a5cbe1e99e3d8b0cc5bf37d7167398d --- extendedcommands.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/extendedcommands.c b/extendedcommands.c index 29adf56..c79836e 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -214,6 +214,21 @@ char** gather_files(const char* directory, const char* fileExtensionOrDirectory, return NULL; } + // sort the result + if (files != NULL) { + for (i = 0; i < total; i++) { + int curMax = -1; + int j; + for (j = 0; j < total - i; j++) { + if (curMax == -1 || strcmp(files[curMax], files[j]) < 0) + curMax = j; + } + char* temp = files[curMax]; + files[curMax] = files[total - i - 1]; + files[total - i - 1] = temp; + } + } + return files; }