Untitled
unknown
plain_text
2 years ago
670 B
5
Indexable
#include <stdio.h> #include <stdlib.h> #include <string.h> int cmp(const void *a, const void *b) { return strcmp(*(char **) a, *(char **) b); } int main() { char text[1000]; char *subStr = malloc(30 * sizeof(char)); int count = 1; fgets(text, 1000, stdin); fgets(subStr, 30, stdin); for (int i = 0; i < strlen(text); i++) if (text[i] == ' ') count++; char **words = malloc(sizeof(char *) * count); words[0] = strtok(text, " ."); for (int i = 1; i < count; i++) words[i] = strtok(NULL, " ."); qsort(words, count, sizeof(char *), cmp); if (bsearch(&subStr, words, count, sizeof(char *), cmp)) puts("exists"); else puts("doesn't exist"); return 0; }
Editor is loading...