From the course: C Standard Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Sort and search functions

Sort and search functions - C Tutorial

From the course: C Standard Library

Start my 1-month free trial

Sort and search functions

- [Instructor] So let's write the compare function in line 10. Now remember that the prototype of this function is already specified in the definition of q search and b search. So it has to return an integer. You can name it however you want. I will call it my compare. And the arguments have to be two void pointers. And they have to be defined with the const qualifier so that's const void pointer. I will call the first one left hand side, and the second one, right hand side. And the implementation will be very simple. I will simply subtract left hand side minus right hand side. But we have to do this in a clever way, so that the compiler knows that we want to subtract integers because remember, these arguments are void pointers so they may be anything. What this means is that I have to cast a lot of variables here. Let me show you how. So I will return a subtraction. Now this subtraction will be, left hand side, with the in direction operator minus whatever right hand side points to…

Contents