utils.c 404 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "defs.h"
  2. #include "utils.h"
  3. int word_exists_in_sentence_prior_to(sentence_info* s, int index) {
  4. int word = s->word_list[index];
  5. for(int i = index - 1; i >= 0; i--) {
  6. if(s->word_list[i] == word) return 1;
  7. }
  8. return 0;
  9. }
  10. int int_cmp(int* a, int* b) {
  11. return *a - *b;
  12. }
  13. void sort_words(int* words, int len) {
  14. qsort(words, len, sizeof(*words), (void*)int_cmp);
  15. }