Blame view

projet.c~ 1.07 KB
327fa977   mduquesn   final
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
  #include <stdio.h>
  #include <string.h>
  #include <stdlib.h>
  #include <stdbool.h>
  
  struct cell {
    int stop;
    struct cell * liste[26];
  };
  
  int num(char c){
    return 1;
  }
  
  int ajout_mot(struct cell ** d,char * m){
    char c;
    struct cell **tmp1 , *tmp2 ;
    int x=0;
    if (*d==NULL){return EXIT_FAILURE;}
    tmp1=d;
    c=m[x];
    while (c!="\0"){
      printf("%c",c);
      if ((*tmp1)->liste[num(c)]==NULL){
        tmp2=malloc(sizeof(struct cell));
        (*tmp1)->liste[num(c)]=tmp2;
      }
      tmp1=&((*tmp1)->liste[num(c)]);
      x++;
      c=m[x];
    }
    return 1;
  }
  
  void creation_dico(FILE *fd,struct cell **d){
    char s[20];
    while (fscanf(fd,"%s",s)==1){
      ajout_mot(d,s);
    }
  }
  
  int main(int argc, char *argv[])
  {
  	if (argc < 2)
  	{
  		fprintf(stderr, "usage: hash <file_name>\n");
  		return EXIT_FAILURE;
  	}
  
  	FILE *fp;
  	printf("%s\n",argv[1]);
  	fp=fopen(argv[1], "r");
  	if (fp==NULL)
  	{
  		fprintf(stderr, "no such file, or unreachable: %s\n", argv[1]);
  		return EXIT_FAILURE;
  	}
  	struct cell *d;
  	d=malloc(sizeof(struct cell));
  	//creation_dico(fp,&d);
  	char s[]="helo\0";
  	ajout_mot(&d,s);
  	
  }