Also, qsort has a friend called bsearch.
If you look at the example here:
https://man7.org/linux/man-pages/man3/bsearch.3.html
First the array is sorted by name. Then bsearch is used for lookup. If the array had millions, using bsearch is a lot faster, because it doesn't have to search through the entire array. And the comparison function is the same.