void change() { pdevice p=NULL,q=NULL; int num; printf("请输入设备编号\n"); scanf("%d",&num); if(find(&p,&q,&num)==0) { printf("该编号不存在请重新输入"); return; } for(;;) { printf("请选择修改项目(编号不可修改)\n"); printf("修改设备名称输入1\n修改设备所在实验室输入2\n修改使用者姓名输入3\n修改设备价格输入4\n修改设备种类输入5\n修改设备购买日期输入6\n"); printf("不再进行修改输入7\n"); int a; scanf("%d",&a); getchar(); if(a!=7) printf("请输入修改后的信息:\n"); getchar(); switch(a) { case 1:gets(q->name);break; case 2:gets(q->position);break; case 3:gets(q->user);break; case 4:scanf("%lf",&(q->price));getchar();break; case 5:delete_type(q->Class);gets(q->Class);insert_type(q->Class);break;//设备种类 case 6:gets(q->date);break; } if(a==7) return; getchar(); } }
ERROR_CODE free_type(struct type_t *type) { /* allocats space for the current type in iteration for the iterator and for the possible hash map element */ struct type_t *current; struct iterator_t *iterator; struct hash_map_element_t *element; /* switches over the type's type in order to execute the proper free operation */ switch(type->type) { case INTEGER_TYPE: /* breaks the switch */ break; case FLOAT_TYPE: /* breaks the switch */ break; case STRING_TYPE: FREE(type->value.value_string); /* breaks the switch */ break; case LIST_TYPE: create_iterator_linked_list(type->value.value_list, &iterator); while(TRUE) { get_next_iterator(iterator, (void **) ¤t); if(current == NULL) { break; } free_type(current); } delete_iterator_linked_list(type->value.value_list, iterator); delete_linked_list(type->value.value_list); /* breaks the switch */ break; case MAP_TYPE: create_element_iterator_hash_map(type->value.value_map, &iterator); while(TRUE) { get_next_iterator(iterator, (void **) &element); if(element == NULL) { break; } free_type((struct type_t *) element->value); } delete_iterator_hash_map(type->value.value_map, iterator); delete_hash_map(type->value.value_map); /* breaks the switch */ break; case SORT_MAP_TYPE: create_element_iterator_sort_map(type->value.value_sort_map, &iterator); while(TRUE) { get_next_iterator(iterator, (void **) &element); if(element == NULL) { break; } free_type((struct type_t *) element->value); } delete_iterator_sort_map(type->value.value_sort_map, iterator); delete_sort_map(type->value.value_sort_map); /* breaks the switch */ break; default: /* breaks the switch */ break; } /* deltes the base type structure for the current type, this applies to all the types */ delete_type(type); /* raises no error */ RAISE_NO_ERROR; }