fix addItem in dict

main
Simon Frei 4 years ago
parent 9c233427fa
commit 3294c8770d
  1. 10
      ADIS_tinyK22_SplitFlap/source/lib/dict.c
  2. 5
      ADIS_tinyK22_SplitFlap/source/splitflap.c
  3. 80
      ADIS_tinyK22_SplitFlap/source/splitflap_flaps.h

@ -6,6 +6,8 @@
*/ */
#include "dict.h" #include "dict.h"
#include <stdlib.h>
#include <string.h>
dict_t** dictAlloc(void){ dict_t** dictAlloc(void){
return malloc(sizeof(dict_t)); return malloc(sizeof(dict_t));
@ -47,9 +49,11 @@ void delItem(dict_t** dict, char* key){
} }
void addItem(dict_t** dict, char* key, void* value){ void addItem(dict_t** dict, char* key, void* value){
delItem(dict, key); // if item already exists delete it! if(((dict_t*)dict)->key !=NULL){
dict_t *d = malloc(sizeof(struct dict_t_struct)); // new dict delItem(dict, key); // if item already exists delete it!
d->key = malloc(strlen(key)+1); }
dict_t *d = (dict_t*)malloc(sizeof(struct dict_t_struct)); // new dict
d->key = (char*)malloc(strlen(key)+1);
// set values // set values
strcpy(d->key, key); strcpy(d->key, key);
d->value = value; d->value = value;

@ -13,10 +13,13 @@
#include "lib/dict.h" #include "lib/dict.h"
#include "splitflap_flaps.h" #include "splitflap_flaps.h"
static dict_t **splitFlapDict; dict_t **splitFlapDict;
void SF_InitConfig(void){ void SF_InitConfig(void){
splitFlapDict = dictAlloc(); splitFlapDict = dictAlloc();
((dict_t*)splitFlapDict)->key=NULL;
((dict_t*)splitFlapDict)->value=NULL;
((dict_t*)splitFlapDict)->next=NULL;
addItem(splitFlapDict, SF_A, 0); addItem(splitFlapDict, SF_A, 0);
addItem(splitFlapDict, SF_B, 0); addItem(splitFlapDict, SF_B, 0);
addItem(splitFlapDict, SF_C, 0); addItem(splitFlapDict, SF_C, 0);

@ -9,46 +9,46 @@
#define SPLITFLAP_FLAPS_H_ #define SPLITFLAP_FLAPS_H_
#include <string.h> #include <string.h>
#define SF_A (char*)'A' #define SF_A "A"
#define SF_B (char*)'B' #define SF_B "B"
#define SF_C (char*)'C' #define SF_C "C"
#define SF_D (char*)'D' #define SF_D "D"
#define SF_E (char*)'E' #define SF_E "E"
#define SF_F (char*)'F' #define SF_F "F"
#define SF_G (char*)'G' #define SF_G "G"
#define SF_H (char*)'H' #define SF_H "H"
#define SF_I (char*)'I' #define SF_I "I"
#define SF_J (char*)'J' #define SF_J "J"
#define SF_K (char*)'K' #define SF_K "K"
#define SF_L (char*)'L' #define SF_L "L"
#define SF_M (char*)'M' #define SF_M "M"
#define SF_N (char*)'N' #define SF_N "N"
#define SF_O (char*)'O' #define SF_O "O"
#define SF_P (char*)'P' #define SF_P "P"
#define SF_Q (char*)'Q' #define SF_Q "Q"
#define SF_R (char*)'R' #define SF_R "R"
#define SF_S (char*)'S' #define SF_S "S"
#define SF_T (char*)'T' #define SF_T "T"
#define SF_U (char*)'U' #define SF_U "U"
#define SF_V (char*)'V' #define SF_V "V"
#define SF_W (char*)'W' #define SF_W "W"
#define SF_X (char*)'X' #define SF_X "X"
#define SF_Y (char*)'Y' #define SF_Y "Y"
#define SF_Z (char*)'Z' #define SF_Z "Z"
#define SF_0 (char*)'0' #define SF_0 "0"
#define SF_1 (char*)'1' #define SF_1 "1"
#define SF_2 (char*)'2' #define SF_2 "2"
#define SF_3 (char*)'3' #define SF_3 "3"
#define SF_4 (char*)'4' #define SF_4 "4"
#define SF_5 (char*)'5' #define SF_5 "5"
#define SF_6 (char*)'6' #define SF_6 "6"
#define SF_7 (char*)'7' #define SF_7 "7"
#define SF_8 (char*)'8' #define SF_8 "8"
#define SF_9 (char*)'9' #define SF_9 "9"
#define SF_EXCLAMATION (char*)'!' #define SF_EXCLAMATION "!"
#define SF_QUESTION (char*)'?' #define SF_QUESTION "?"
#define SF_COLON (char*)':' #define SF_COLON ":"
#define SF_SPACE (char*)' ' #define SF_SPACE " "

Loading…
Cancel
Save