From 057a1cb40289150b2f3c8a81c18cbbb5cd2d32c8 Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Thu, 16 Nov 2017 13:19:50 -0500 Subject: [PATCH] Compile all thread-returned structs into a single pointer Last step before combining all arrays into one sorted dataset. --- Main.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Main.c b/Main.c index e2127c7..0b4b0df 100644 --- a/Main.c +++ b/Main.c @@ -81,8 +81,8 @@ int main(int argc, char* argv[]) { int index; int return_int; int struct_number; - data_struct* data_array; thread_return_struct* return_struct; + thread_return_struct** thread_arrays; // Check for valid args. if (argc < 2) { @@ -104,26 +104,30 @@ int main(int argc, char* argv[]) { // Open folder and create appropriate number of threads. open_folder(); + thread_arrays = calloc(dir_file_counter, sizeof(*return_struct)); + // Iterate through all threads and grab returned value. for (index = 0; index < dir_file_counter; index++) { pthread_join(thread_array[index], (void**) &return_struct); - data_array = return_struct->data_array; - for (struct_number = 0; struct_number <= return_struct->array_count; struct_number++) { - printf("User: %-16s ", data_array[struct_number].user_name); - printf("Password: %-17s ", data_array[struct_number].password); - printf("Blood Type: %-7s ", data_array[struct_number].blood_type); - printf("Domain: %-28s ", data_array[struct_number].domain_name); - printf("DB Index: %-15d \n", data_array[struct_number].db_index); - free(data_array[struct_number].user_name); - free(data_array[struct_number].password); - free(data_array[struct_number].blood_type); - free(data_array[struct_number].domain_name); + + thread_arrays[index] = return_struct; + + for (struct_number = 0; struct_number <= thread_arrays[index]->array_count; struct_number++) { + printf("User: %-16s ", thread_arrays[index]->data_array[struct_number].user_name); + printf("Password: %-17s ", thread_arrays[index]->data_array[struct_number].password); + printf("Blood Type: %-7s ", thread_arrays[index]->data_array[struct_number].blood_type); + printf("Domain: %-28s ", thread_arrays[index]->data_array[struct_number].domain_name); + printf("DB Index: %-14d \n", thread_arrays[index]->data_array[struct_number].db_index); + free(thread_arrays[index]->data_array[struct_number].user_name); + free(thread_arrays[index]->data_array[struct_number].password); + free(thread_arrays[index]->data_array[struct_number].blood_type); + free(thread_arrays[index]->data_array[struct_number].domain_name); } - free(data_array); + free(thread_arrays[index]->data_array); free(return_struct); printf("\n\n"); } - + free(thread_arrays); free(absolute_path); free(thread_array); } -- GitLab