diff --git a/c-programming/reverse-ramdisk.c b/c-programming/reverse-ramdisk.c index da14f2a..56ec4ce 100644 --- a/c-programming/reverse-ramdisk.c +++ b/c-programming/reverse-ramdisk.c @@ -81,12 +81,14 @@ int tf_alloc(size_t n, size_t type_size) { return -1; } - // Assign the ID and file path + // Assign the ID, file path, file handler temp_file->ID = num_temp_files; temp_file->file_path = strdup(file_path); temp_file->file = file; - // Increase the number of temp files + // Add the temp file to the array + temp_files[num_temp_files] = *temp_file; + num_temp_files++; // Allocate/reallocate memory for the temp_files structure @@ -100,9 +102,6 @@ int tf_alloc(size_t n, size_t type_size) { return -1; } - // Add the temp file to the array - temp_files[num_temp_files - 1] = *temp_file; - return temp_file->ID; }