online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZEOF_ARRAY(array) (sizeof(array) / sizeof(*array)) int compare(const void *lhs, const void *rhs) { const char *l = *(const char * const *) lhs; const char *r = *(const char * const *) rhs; if (l < r) return -1; if (l > r) return 1; return 0; } int main() { const char *data[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; size_t size = SIZEOF_ARRAY(data); qsort(data, size, sizeof(const char *), compare); for (size_t i = 0; i < size; ++i) { printf("%s\n", data[i]); } printf("\n"); const char July[] = "July"; const char *val = July; const char **ans = (const char **) bsearch(&val, data, size, sizeof(const char *), compare); if (ans != NULL) printf ("\"%s\"found on index %td\n", *ans, (ans - data)); else printf ("\"%s\" not found\n", val); return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue