I need to sort filenames that can have a common root, but are then followed by numbers that are not necessarily padded uniformely; one example is what you obtain when you rename multiple files in Windows.
filenamea (1).txt
filenamea (2).txt
…
filenamea (10).txt
…
filenamea (100).txt
…
filenameb.txt
…
filenamec (1).txt
filenamec (2).txt
and so on…
There are already similar questions, I know of Sort on a string that may contain a number and How to implement a natural sort algorithm in C. So you can also look there for more inspiration and help.
Both questions’ answers suggest, http://www.davekoelle.com/alphanum.html, which is basically what Pascal Cuoq suggested.
You can also look at the Coding Horror article, where some other algorithms are linked: Sorting for Humans : Natural Sort Order