I am just getting into the various search methods/functions/algorithms available in C. The only function I have come across in the K&R book or online in example C code is the 'qsort' function. I have learned how it works watching some youtube videos, and I know how to sort a list of integers or strings using it. In the example code that I have found online, qsort always uses the ASCII values of each character in a string in a 'comparison function' to return a positive number, negative number, or zero. This is convenient if one wants to sort an array of strings alphabetically, since the value of 'a' < 'b' < 'c' < 'd' < 'e'.... in ASCII.
I want to know how to sort a list of strings some other way. I do not want to do it alphabetically, and thus I need to know how to setup a comparison function to sort strings differently, using some sort of legend or key that I designate.
For example, say I had a list of positions in a company, and I wanted to sort a list of company positions. If 'President' were the most powerful position, and I wanted it at the top of my list after sorting, how could I define President as the 'number 1' position, meaning it should be sorted to the front of the list, (not based on the value of 'P' in ASCII, which might throw 'President' to the middle or end of the list).
I'm very new to programming, so I'm not familiar with all of the tools at my disposal. The only method I have thought of on my own is to create a new array of integers and assign numerical values to certain specific strings. Then, perform qsort on an array of integers, and then take that newly created array and convert it back to the corresponding strings. This converting to integers and converting back to strings seems like it would be inefficient, but I don't know of a better way due to my programming ignorance. Should I use qsort another way? Should I use some other function besides qsort for this task?