Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int cmp (const void * a, const void * b)
- {
- return (strcmp(*(char**)a, *(char**)b));
- }
- int main() {
- char source[1001];
- char patch[31];
- fgets(source, 1001, stdin);
- fgets(patch, 31, stdin);
- source[strlen(source)] = '\0';
- //printf("%s\n", source);
- patch[strlen(patch)] = '\0';
- //printf("============>>>>>>>>>%s\n", patch);
- char** arr = NULL;
- int n = 0;
- char * ptr = strtok(source, " .");
- while (ptr != NULL)
- {
- arr = realloc(arr, (n+1) * sizeof(char*));
- arr[n] = ptr;
- //printf("%s\n", arr[n]);
- n++;
- ptr = strtok(NULL, " .");
- }
- qsort(arr, n, sizeof(char*), cmp);
- //printf("============\n");
- //for(int i=0; i<n; i++)
- //printf("{%s}\n",arr[i]);
- char** patch_p = (char **) &patch;
- ptr = (char*)bsearch(&patch_p, arr, n, sizeof(char*), cmp);
- if(ptr)
- printf("exists\n");
- else
- printf("doesn't exist\n");
- free(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement