-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordcount.c
executable file
·53 lines (43 loc) · 1.08 KB
/
wordcount.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* wordcount.c
* IJC-DU2, 15.4. 2011
* Autor: Ondrej Machacek, FIT
* Prelozeni gcc 4.5.1
* Funkce pro testovani implementace htable,
*/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "io.h"
#include "htable.h"
#define HTABLE_SIZE 8192
int main() {
FILE *f = stdin;
// f = fopen("/home/Ondra/ahoj1.txt", "r"); // smazat
char string[MAX_LEN];
int len;
htable_t* table = htable_init(HTABLE_SIZE);
htable_listitem *item;
while ( (len = fgetword(string, MAX_LEN, f)) != 0 ) {
if((item = htable_lookup(table, string)) == NULL) {
fprintf(stderr, "Chyba pri alokaci pameti.\n");
return EXIT_FAILURE;
}
}
// fclose(f); //smazat
htable_iterator b = htable_begin(table);
htable_iterator *bg = &b;
htable_iterator end = htable_end(table);
while( !htable_iter_eq(bg, &end) ) {
if(htable_iter_deref(bg) == NULL)
break;
printf("%s\t%d\n", bg->ptr->key, bg->ptr->data);
bg = htable_iter_next(bg);
}
if(end.ptr != NULL)
printf("%s\t%d\n", end.ptr->key, end.ptr->data);
// Uklid haldu
htable_free(table);
return EXIT_SUCCESS;
}