Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- int cmp(const void* a, const void* b){
- const char** f = (const char**)a;
- const char** g = (const char**)b;
- return strcmp(*f, *g);
- }
- int cmp1 (const void* key, const void* val){
- const char* k = (const char*)key;
- const char** v = (const char**)val;
- return strcmp(k, *v);
- }
- int main() {
- char arr [1002];
- char* pointer [502];
- char str [32];
- fgets(arr, 1002, stdin);
- fgets(str, 32, stdin);
- str[strcspn(str, "\n")] = '\0';
- arr[strcspn(arr, "\n")] = '\0';
- char* pch = strtok(arr," .");
- int m = 0;
- while (pch != NULL){
- pointer[m] = pch;
- m++;
- pch = strtok(NULL, " .");
- }
- int len_str = (int) strlen(str);
- // str[len_str - 1] = '\0';
- int len = m;
- qsort(pointer, len, sizeof(char*), cmp);
- char** result = (char**) bsearch(str, pointer, len, sizeof(char*), cmp1);
- if (result)
- printf("exists");
- else
- printf("doesn't exist");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement