void hash_clean ( struct Hash *hash, void (* func)( void *) ) { int i; struct hash_bucket *mp = NULL; struct hash_bucket *next = NULL; void * data = NULL; if(NULL == hash){ return ; } for ( i = 0; i < hash->size; i++ ) { for ( mp = hash_head ( hash, i ,0); mp; mp = next ) { next = mp->next; data = hash_pull(hash,mp->data); if (func&&data) { (*func)(data); } /*free(mp);*/ } /* FOR (...) */ hash->index[ i ] = NULL; } /* FOR (...) */ hash->count = 0; }
int main(int argc, char *argv[]) { if (argc != 3) { printf("Incorrect number of arguments. Run again\n"); return EXIT_FAILURE; } else { if(strcmp(argv[2], ".") == 0 || strcmp(argv[2], "..") == 0){ printf("Error: Cannot utilize parent directory or current working directory as input.\n"); return EXIT_FAILURE; } if(strcmp(argv[2],"") == 0){ printf("Error: Starting file or directory is NULL\n"); return EXIT_FAILURE; } ht = ht_create(); out_path = argv[1]; if(get_Files(argv[2]) == -1) { printf("File read fails. Invalid start input\n"); return EXIT_FAILURE; } } Record** rec_array; rec_array = hash_pull(ht); qsort(rec_array, ht->size, sizeof(Record*), rec_compare); print_json(rec_array); ht_free(ht); free(rec_array); return 0; }