Write a program sorta that sorts and prints its arguments. sorta takes zero or more arguments, sorts them lexicographically, and then prints each argument on its own line. If sorta receives no arguments, it should exit without printing anything.
Write a
sorts them lexicographically, and then prints each argument on its own line.
If sorta receives no arguments, it should exit without printing anything.
You are free to use any sorting
for string comparison. Note that strcmp() uses lexicographical ordering (so a string comes after
its prefix) based on ASCII comparison of characters (so ‘Z’ comes before ‘a’). (See man strcmp for usage information.)
Treat the arguments (excluding argv[0]) as given: make no attempt to process or otherwise normalize the strings before sorting. Note that your shell will perform some manipulation on your input before passing the strings to your program, and most punctuation marks have special meanings: use escape sequences and/or quotation marks to avoid this.
Program should not assume that it has received the proper number of arguments, for example, but
should check and report an error where appropriate.
Usage
$ ./sorta foo bar baz quuz
bar
baz
foo
quux
$ ./sorta aaa aAa AaA AAA
AAA
AaA
aAa
aaa
$ ./sorta 3 20 100
100
20
3
$ ./sorta " z" a
z
a
C Programming which refers to the object oriented programming languages. C programming language which refers to the machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games etc.
Step by step
Solved in 3 steps