Created
August 5, 2017 17:40
-
-
Save nickolasburr/48dffebf52d3f4f7b694d79cb9bba241 to your computer and use it in GitHub Desktop.
Check if a string exists in an array.
This file contains 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 <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