Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #define BUFFER 100
- #define WORD_LEN 100
- #define TRUE 1
- #define FALSE 0
- typedef struct Dictionary {
- char **keys;
- char **values;
- int size;
- } dict;
- dict *createDictionary(int size) {
- dict *dictionary = (dict *) malloc(sizeof(dict *));
- dictionary->size = size;
- dictionary->keys = (char **) malloc(sizeof(char **) * dictionary->size);
- dictionary->values = (char **) malloc(sizeof(char **) * dictionary->size);
- for(int i = 0; i < BUFFER; i++){
- dictionary->keys[i] = malloc(sizeof(char *) * WORD_LEN);
- dictionary->values[i] = malloc(sizeof(char *) * WORD_LEN);
- }
- return dictionary;
- }
- int main() {
- dict *dict1 = createDictionary(BUFFER);
- int n = 0;
- char input[WORD_LEN];
- while (TRUE) {
- scanf("%s", input);
- if (strcmp(input, "ugabuga") == 0)
- break;
- strcpy(dict1->keys[n], input);
- scanf("%s", dict1->values[n]);
- n++;
- }
- while (scanf("%s", input) != EOF) {
- int found = FALSE;
- for (int i = 0; i < n; i++) {
- if (strcasecmp(input, dict1->keys[i]) == 0) {
- printf("%s", dict1->values[i]);
- found = TRUE;
- break;
- }
- }
- if (!found)
- printf("<unknown>");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement