Skip to content

Instantly share code, notes, and snippets.

@mwotton
Created January 9, 2017 23:56
Show Gist options
  • Save mwotton/8a17d399bd9763dd891474e34e1e1668 to your computer and use it in GitHub Desktop.
Save mwotton/8a17d399bd9763dd891474e34e1e1668 to your computer and use it in GitHub Desktop.
#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