-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
118 lines (93 loc) · 3 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "dict.h"
#include "langdt.h"
#include <stdlib.h>
char *
receiveLanguageCode(char * text);
int main(){
char *text= "are would could monday tuesday friday wednesday 再见 Hello! We are lear'ning about strtok the است we ";
char language_code[6];
strcpy(language_code,receiveLanguageCode(text));
printf("Language >> %s \n",language_code);
}
char *
receiveLanguageCode(char * text){
int TOTAL_APPS=3;
//adding to list vars
char buf[512];
int c=1;
int current_Count=0;
char final_lang[6]="other";
Dict DATA,RESULT_DICT;
DATA=getClassLanguages();
RESULT_DICT=DictCreate();
//DictInsert(d, "foo", "hello world");
//to lowercase and writable
char *string= strlwr(strdup(text));
//Extract the first token
char * token = strtok(string, " ");
//char * word=;
//DictInsert(RESULT_DICT, "foo", "45");
//int count=atoi(DictSearch(RESULT_DICT,"foo"));
//printf("%d\n",count);
while( token != NULL ) {
//printf( "%s\n", token );
char* fromDict=DictSearch(DATA,token);
//checking in Data
if(fromDict==0){
//printf("%s : Not found\n",token);
}else{
//printf("%s >> %s: found\n",token,fromDict);
char* fromResult=DictSearch(RESULT_DICT,fromDict);
if(fromResult==0){
//Add to the list
sprintf(buf, "%d", c);
//DictInsert(RESULT_DICT, buf, buf);
DictInsert(RESULT_DICT,fromDict,buf);
}else{
//Increase counter
current_Count=atoi(DictSearch(RESULT_DICT,fromDict));
//printf("%s count >> %d\n",fromDict,current_Count);
sprintf(buf, "%d", ++current_Count);
DictInsert(RESULT_DICT,fromDict,buf);
if(current_Count>TOTAL_APPS){
//printf("Target here >> %s ***********\n",fromDict);
strncpy(final_lang,fromDict,sizeof(fromDict));
break;
}
}//2nd if
}//end of main_if
//firs
//check if the word is in LangFiles
token = strtok(NULL, " ");
}
DictDestroy(DATA);
DictDestroy(RESULT_DICT);
//free(word);
return final_lang;
}
int
mainRed()
{
Dict d;
char buf[512];
int i;
d = DictCreate();
DictInsert(d, "foo", "hello world");
//puts(DictSearch(d, "foo"));
//DictInsert(d, "foo", "hello world2");
//puts(DictSearch(d, "foo"));
//DictDelete(d, "foo");
//puts(DictSearch(d, "foo"));
//DictDelete(d, "foo");
assert(DictSearch(d, "foo") == 0);
//DictDelete(d, "foo");
for(i = 0; i < 10000; i++) {
sprintf(buf, "%d", i);
DictInsert(d, buf, buf);
}
DictDestroy(d);
return 0;
}