Join Eduardo Corpeño for an in-depth discussion in this video Sort and search functions, part of C Standard Library.
- [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.…But we have to cast these pointers to integer pointers,…
- Working with header files
- C constants and types
- Unformatted and formatted input/output
- Accessing files with C functions
- Generating random numbers
- Converting strings
- Sorting and searching for data
- Manipulating strings
- Using mathematical functions
Skill Level Intermediate
1. The C Standard Library
2. Input and Output Library: stdio.h
3. General Purpose: stdlib.h
4. String Functions: string.h
5. Mathematical Functions: math.h
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.