Created
January 9, 2017 23:56
-
-
Save mwotton/8a17d399bd9763dd891474e34e1e1668 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
extern unsigned int keylookup[]; | |
extern char * toASCIILut[]; | |
int comparator(const void * key, const void * member) { | |
unsigned int keyU = (*((unsigned int*) key)); | |
unsigned int memberU = (*((unsigned int *) member)); | |
if (keyU < memberU) { | |
return -1; | |
} else if (keyU > memberU) { | |
return 1; | |
} | |
return 0; | |
} | |
char * findString(unsigned int index) { | |
unsigned int * out_index = bsearch(&index, &keylookup, 8922, sizeof(unsigned int), &comparator); | |
if (out_index==NULL) { | |
// not found | |
return ""; | |
} else { | |
return toASCIILut[out_index - keylookup]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment