[cs631apue] sorting files containing a dot

Patrick Murray pmurray1 at stevens.edu
Thu Sep 22 00:16:24 EDT 2016


Evening Marlon,

The strange output you've encountered is the result of strcmp(3) performing
a
case-sensitive comparison. Since uppercase characters appear first in the
ASCII
table, they will appear first in your output. [0]

To my knowledge, C does not come shipped with a case-insensitive comparison
function; as a result, you'll have to implement your own using tolower(3)
or a
similar tool. From this lowercase string (or uppercase- it doesn't matter as
long as it's consistent), strcmp(3) will be able to compare the filenames
properly.

[0] https://en.wikipedia.org/wiki/ASCII

- Pat

On Wed, Sep 21, 2016 at 11:31 PM, mseaton <mseaton at stevens.edu> wrote:

> Hello,
> the standard ls sorts files stored in directories. My files that contains
> a . seems to "throw off" the sorting a bit. for example:
>
> Here are a list of files from my /home/mseaton directory:
>
> Desktop
> Documents
> Downloads
> Music
> NewFolder
> Pictures
> PrintBlocks.c
> Public
> SortFileSize.c
> Templates
> Videos
> examples.desktop
> file1
> functions.h
> headers.h
> ls
> ls.c
> ls.c~
> mozilla.pdf
>
> As you can see, examples.desktop and a few others are out of place. Any
> suggestion for how to handle the files with the .? I was planning on
> removing the dots, sort the files and somehow put the dots back in its
> place, but this does not seem possible.
>
> Marlon
> _______________________________________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/mailman/listinfo/cs631apue
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20160922/1cc11986/attachment.html>


More information about the cs631apue mailing list