Yes, it has been asked before and i have followed the advice here and put my declerations at the top still not working.
void map_delete(map_t *map, char *key) {
assert(map_contains(map, key));
map_elem_t *prev;
map_elem_t *elem_to_remove;
prev = map->elem;
while(strcmp(prev->next->key, key) != 0) prev= prev->next;
elem_to_remove = prev->next;
prev->next = elem_to_remove->next;
free(elem_to_remove);
}
map.c(74): error C2143: syntax error : missing ';' before 'type'
map.c(76): error C2065: 'prev' : undeclared identifier
map.c(76): warning C4047: '=' : 'int' differs in levels of indirection from 'map_elem_t *'
map.c(77): error C2065: 'prev' : undeclared identifier
map.c(77): error C2223: left of '->next' must point to struct/union
map.c(77): error C2198: 'strcmp' : too few arguments for call
map.c(77): error C2065: 'prev' : undeclared identifier
map.c(77): error C2065: 'prev' : undeclared identifier
map.c(77): error C2223: left of '->next' must point to struct/union
map.c(79): error C2065: 'elem_to_remove' : undeclared identifier
map.c(79): error C2065: 'prev' : undeclared identifier
map.c(79): error C2223: left of '->next' must point to struct/union
map.c(80): error C2065: 'prev' : undeclared identifier
map.c(80): error C2223: left of '->next' must point to struct/union
map.c(80): error C2065: 'elem_to_remove' : undeclared identifier
map.c(80): error C2223: left of '->next' must point to struct/union
map.c(81): error C2065: 'elem_to_remove' : undeclared identifier
map.c(81): warning C4022: 'free' : pointer mismatch for actual parameter 1
note the logic of the code is correct as it was working on another machine, its the compiler that is not happy with the layout
The compiler complains because assert
is not a declaration. You'll need to move the assert
so that it comes after the declarations.
Using a C compiler that supported a standard more recent that C89 would be a good move.