Search code examples
ckernighan-and-ritchie

K&R Task Exercise 5.17


Can someone explain what specifically needs to be done in exercise 5.17, what does it mean to sort within line, its field?


Solution

  • I don't have my copy of K&R here. I think it means this

    Suppose the original file has

    0000087423 Volkswagen 2001-01-01
    0000642396 Fiat 2002-02-02
    3900063521 Renault 2003-03-03
    

    It is already sorted by the 1st field; if you want to sort it by the 2nd field (the name) the result would be

    0000642396 Fiat 2002-02-02
    3900063521 Renault 2003-03-03
    0000087423 Volkswagen 2001-01-01
    

    Or you can sort by date (the 3rd field)