Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. struct entry
  5. {
  6. char word[15];
  7. char definition[50];
  8. };
  9.  
  10. bool equalStrings(const char s1[], const char s2[]);
  11. int lookup(const struct entry dictionary[], const char search[], const int entries);
  12.  
  13. int main(void)
  14. {
  15. const struct entry dictionary[100] =
  16. {{ "aardvark", "a burrowing African mammal"},
  17. { "abyss", "a bottomless pit"},
  18. { "acumen", "mentally sharp; keen"},
  19. { "addle", "to become confused"},
  20. { "aerie", "a high nest"},
  21. { "affix", "to append; attach"},
  22. { "agar", "a jelly made from seaweed"},
  23. { "ahoy", "a nautical call of greeting"},
  24. { "aigrette", "an ornamental cluster of feathers"},
  25. { "ajar", "partially opened"}};
  26.  
  27.  
  28. char word[10];
  29. int entries = 10;
  30. int entry;
  31.  
  32. printf("Enter word: ");
  33. scanf("%14s", word);
  34. entry = lookup(dictionary, word, entries);
  35.  
  36. if(entry != -1)
  37. printf("%sn", dictionary[entry].definition);
  38. else
  39. printf("Sorry, the word %s is not in my dictionaryn", word);
  40.  
  41. return 0;
  42. }
  43.  
  44. bool equalStrings(const char s1[], const char s2[])
  45. {
  46. int i = 0;
  47. bool areEqual;
  48.  
  49. while(s1[i] == s2[i] && s1[i] != '' && s2[i] != '')
  50. {
  51. i++;
  52. }
  53. if(s1[i] == '' && s2[i] == '')
  54. areEqual = true;
  55. else
  56. areEqual = false;
  57.  
  58. return areEqual;
  59. }
  60.  
  61. int lookup(const struct entry dictionary[], const char search[], const int entries)
  62. {
  63. int i;
  64. bool equalStrings(const char s1[], const char s2[]);
  65.  
  66. for(i = 0; 1 < entries; i++)
  67. {
  68. if(equalStrings(search, dictionary[i].word))
  69. {
  70. return i;
  71. }
  72. }
  73. return -1;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement