Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5.  
  6. #include"symtable.h"
  7.  
  8.  
  9. typedef struct node{
  10.  
  11. char *key;
  12. int value;
  13. struct node *next;
  14.  
  15. }node;
  16.  
  17.  
  18. struct Symtable {
  19.  
  20. node *sym_head;
  21.  
  22. };
  23.  
  24. /*Iniatialize a new Symbol Table*/
  25. SymTable_T SymTable_new(void){
  26.  
  27. SymTable_T symtable = NULL;
  28.  
  29. symtable = malloc(sizeof( SymTable_T ) );
  30.  
  31. if(symtable==NULL){
  32. printf("Memory allocation for---SYMTABLE---FAILED\n");
  33. exit(EXIT_FAILURE);
  34. }
  35.  
  36. // symtable->sym_head = NULL;error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
  37. // node sym_head = NULL;
  38. // ^
  39.  
  40. symtable->sym_head= NULL;
  41. return symtable;
  42. }
  43.  
  44.  
  45. // int SymTable_put(SymTable_T oSymTable,const char *pcKey,const void *pvValue){
  46.  
  47. // /*Checking if the given key is already in the Symbol Table*/
  48. // int exists=SymTable_contains(oSymTable,pcKey);
  49. // if(exists==1){
  50. // printf("This key is in the Symbol Tab,CANT INSERT AGAIN!!!\n");
  51. // return 0;
  52. // }
  53.  
  54. // /* Check Runtime Errors */
  55. // assert(oSymTable != NULL);
  56. // assert(pcKey != NULL);
  57.  
  58. // node *new_node;
  59. // node *list_head = oSymTable->head;
  60.  
  61. // new_node = malloc(sizeof(node));
  62.  
  63. // if(new_node==NULL){
  64. // printf("Memory allocation for ---NEW NODE---FAILED\n");
  65. // exit(EXIT_FAILURE);
  66. // }
  67.  
  68. // /*first node to enter the list*/
  69. // if(oSymTable->head==NULL){
  70.  
  71. // oSymTable->head=new_node;
  72. // new_node->key=pcKey;
  73. // new_node->value=pvValue;
  74. // new_node->next=NULL;
  75.  
  76. // }else{
  77.  
  78. // new_node->key=pcKey;
  79. // new_node->next=oSymTable->head;
  80. // new_node->value=pvValue;
  81. // oSymTable->head=new_node;
  82. // }
  83.  
  84. // return 1;
  85. // }
  86.  
  87.  
  88. int main(){
  89.  
  90.  
  91. SymTable_T sym1 = NULL;
  92. sym1 = SymTable_new();
  93.  
  94.  
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement