Skip to content

Instantly share code, notes, and snippets.

@nickolasburr
Created August 5, 2017 17:40
Show Gist options
  • Save nickolasburr/48dffebf52d3f4f7b694d79cb9bba241 to your computer and use it in GitHub Desktop.
Save nickolasburr/48dffebf52d3f4f7b694d79cb9bba241 to your computer and use it in GitHub Desktop.
Check if a string exists in an array.
#include <string.h>
/**
* Check if a string exists in an array.
*/
int in_array (const char* const str, const char *arr[], size_t size) {
int i;
for (i = 0; i < size; i += 1) {
if (!strcmp(arr[i], str)) {
return 1;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment