Blame view

dico.c 1.17 KB
0bc3d1ad   bjeanlou   dico created
1
2
3
4
5
6
  #include "dico.h"
  
  void make_empty_dico(dico d){
    for(int i=0;i<NB1CHAR;i++)
      d[i]=NULL;
  }
a0fe64d2   bjeanlou   Update dico
7
  void delete_dico(dico d){
0bc3d1ad   bjeanlou   dico created
8
9
10
11
    for(int i=0;i<NB1CHAR;i++)
      delete_tree(d[i]);
  }
  
11c78e6d   bjeanlou   update5 withHash
12
13
14
15
16
17
18
  
  
  bool addto_dico(dico d,string s){
    byte endKind=end_kind(s);
    if(!is_word(endKind)){
      printf("incorrect word");
      return true;
a0fe64d2   bjeanlou   Update dico
19
    }
11c78e6d   bjeanlou   update5 withHash
20
21
22
23
24
25
26
    if(is_empty(d[hash(s[0])])){
       d[hash(s[0])]=make_node(s[0],0);
       addto_tree2(d[hash(s[0])],s+1,endKind);
       return false;
    }
    else {
      return addto_tree(d[hash(s[0])],s+1,endKind);
a0fe64d2   bjeanlou   Update dico
27
    }
a0fe64d2   bjeanlou   Update dico
28
29
  }
  
11c78e6d   bjeanlou   update5 withHash
30
31
32
33
34
35
36
37
38
39
40
41
42
  bool lire(string s,FILE*stream){
    //need to check if stream !=NULL
    //ret true if error else false
      char* posRet=NULL;
      if (fscanf(stream,"%s",s) != NULL){
          posRet=strchr(chaine, '\n');
          if (posRet!= NULL){
              *posRet = '\0';
          }
          return false;
      }
      else 
          return true;
a0fe64d2   bjeanlou   Update dico
43
  }
0bc3d1ad   bjeanlou   dico created
44
  
11c78e6d   bjeanlou   update5 withHash
45
46
47
48
49
  void loadfrom_keyboard(dico d){loadfrom_file(d,stdin);} 
  void loadfrom_file(dico d,FILE*stream){
    if(stream==NULL){
      printf("sorry, we can't open the file");
      return;
62535895   bjeanlou   Update1 dico
50
    }
11c78e6d   bjeanlou   update5 withHash
51
52
53
54
55
56
57
    string str=calloc(30*sizeof(char));
    while(fscanf(""strstream)!=NULL)
  }
  
  void printto_terminal(dico d){printto_file(dico,stdout);} 
  void printto_file(dico d,FILE*f){
    ;
0bc3d1ad   bjeanlou   dico created
58
  }