C - sort and search