Blame view

functions.c 1.09 KB
ccb47d03   bjeanlou   menu quit ok
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
  #include <stdio.h>
  #include "functions.h"
  
  int saisie(int min,int max){
       int n;
      do{scanf("%d",&n);
      }while(n<min || n>max);
      return n;
  }
  
  int ctoi(char c){
    if(c>'9' || c<'0')
      return -1;
    return c-'0';
  }
  
  void clear(){
  #ifdef WIN32
      system("cls");
  #else
      #ifdef UNIX
          system("clear");
      #else
      for(int i=0;i<30;i++)printf("\n");
      #endif
  #endif
  }
  
  void pause(){
      getchar();
      printf("tapez la touche entree");
      fflush(stdout);
      while(getchar()!='\n');
  }
  
  
  
  //stringLIFO
  stringLIFO init_stringLIFO(){return NULL;}
  
  int is_emptyLIFO(stringLIFO list){return list==NULL;}
  
  void delete_LIFO(stringLIFO*list){
    while(!is_emptyLIFO(*list))
      free(pop(list));
  }
  
  string top(stringLIFO list){return is_emptyLIFO(list)?NULL:list->val;}
  
  void push(stringLIFO *list,string s){
    cell*c=malloc(sizeof(cell));
    c->val=calloc((strlen(s)+1),sizeof(char));
    strcpy(c->val,s);
    c->next=*list;
    *list=c;
  }
  
  string pop(stringLIFO*list){
    string ret=NULL;
    if(!is_emptyLIFO(*list)){
      cell*c=(*list)->next;
      ret=(*list)->val;
      free(*list);
      *list=c;
    }
    return ret;
  }