[cs631apue] sorting files containing a dot

mseaton mseaton at stevens.edu
Thu Sep 22 01:27:27 EDT 2016


Thanks Pat. I forgot about that.
Marlon
On 09/22/2016 12:16 AM, Patrick Murray wrote:
> 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 [2]
> 
> - 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 [1]
> 
> 
> 
> Links:
> ------
> [1] https://lists.stevens.edu/mailman/listinfo/cs631apue
> [2] https://en.wikipedia.org/wiki/ASCII


More information about the cs631apue mailing list